Hi,
I have a checkbox connected to a PHP Session variable. Checking and Unchecking the box are supposed to alter the session variable accordingly. However, it seems PHP is unable to recognize scopes for if-else statements within JavaScript event handlers. Is there some global option that will allow it to properly understand the scope? Better yet, is there an all-PHP solution to altering session vars via checkbox states?
Passing the checkbox value in GET or POST is highly inefficient for my site's purposes, seeing as there are about 30 of these buggers at once 🙁 If anybody knows an easy-to-follow tutorial for passing multiple checkboxes via arrays, please paste the link. Thanks!
Example Code
<html>
<head>
<?php
session_start();
session_register('chkbox');
?>
</head>
<body>
<form>
<input type=checkbox name="chk" onClick="
//this is where the fun begins
if (this.form.chk.checked == true) {
<?php $SESSION['chkbox'] = 1; ?>
}
else {
<?php $SESSION['chkbox'] = 2; ?>
}
//this is where it ends
">A checkbox<br>
<input type=button value="session value is" onClick="
alert('<?php echo $_SESSION['chkbox']; ?>');
//note how it registers only the last value regardless of checkbox state
">
</form>
</body>
</html>