sheen4him Posted October 25, 2007 Share Posted October 25, 2007 I am trying to change some variables based on a click of a checkbox. The code is attached. It seems to run the code even on page load. As you can see I set $_SESSION['intspouse'] back to 0, but it is always 1 or 2 when i reload the page. Please help. If you have a better way in PHP that would be fine also. I need to do this in many pages, so the easier the better. Thanks! // near top of page include(_INC_DIR."loadform.php"); $startspouse = $Spouse; $formno=$Occur; if ($_SESSION['intspouse'] == 1) { $Spouse = "X"; $SpOn = "checked"; include(_INC_DIR."updf1099int.php"); include(_INC_DIR."loadform.php"); $_SESSION['intspouse'] = 0; } else if ($_SESSION['intspouse'] == 2) { $Spouse = ""; $SpOn = ""; include(_INC_DIR."updf1099int.php"); include(_INC_DIR."loadform.php"); $_SESSION['intspouse'] = 0; } . . . <input type="checkbox" name="Spouse" value="X" <?echo $SpOn?> onclick="<?if ($Spouse=="") $_SESSION['intspouse']=1; elseif ($Spouse=="X") $_SESSION['intspouse']=2;?>history.go(0)" tabindex='<?echo $tab++?>'>Check if this 1099-Int is for your Spouse</td> Quote Link to comment https://forums.phpfreaks.com/topic/74690-solved-help-with-php-in-onclick/ Share on other sites More sharing options...
trq Posted October 25, 2007 Share Posted October 25, 2007 OnClick is a client side event. PHP runs on the server side. You might want to look into Ajax. Quote Link to comment https://forums.phpfreaks.com/topic/74690-solved-help-with-php-in-onclick/#findComment-377602 Share on other sites More sharing options...
sheen4him Posted October 25, 2007 Author Share Posted October 25, 2007 Thanks, I wasn't thinking. What about a JS? Quote Link to comment https://forums.phpfreaks.com/topic/74690-solved-help-with-php-in-onclick/#findComment-377610 Share on other sites More sharing options...
JJohnsenDK Posted October 25, 2007 Share Posted October 25, 2007 AJAX is like an extension of JS, so if you aint familar with JS learn JS before AJAX Quote Link to comment https://forums.phpfreaks.com/topic/74690-solved-help-with-php-in-onclick/#findComment-377612 Share on other sites More sharing options...
sheen4him Posted October 25, 2007 Author Share Posted October 25, 2007 Thank You! I am just learning JS, so I'll work on that. Quote Link to comment https://forums.phpfreaks.com/topic/74690-solved-help-with-php-in-onclick/#findComment-377615 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.