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> 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. 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? 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 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. 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
Archived
This topic is now archived and is closed to further replies.