View Full Version : Can you assign a php variable a value using JS?

08-31-2006, 06:51 PM
I need to assign a value to a $_SESSION variable and the way I am doing things right now I would need to assign it in a javascript function that is called with an onClick. Is this possible?

08-31-2006, 07:43 PM
Explain better what u wanna do

08-31-2006, 08:00 PM
try like this:

if (isset($_REQUEST['SessionString'])){

<input type='button' onClick="location.href='mypage.php?SessionString=somevalue'" />

08-31-2006, 08:02 PM
I actually decided on a different way to go about my problem and I have it working now.

Here is what I was trying to do:

if($rows != 0 && $_SESSION['skip'] == false){
insert($focus, $createTable = table(array("class"=>"form_input_wide","cols"=>"2")));
$question = "Did you and your spouse view this course together?";
insert($createTable, $createTable_r = heading(1,$question));
insert($createTable, $createTable_r = button(array("name"=>"coupleYes","value"=>"Yes","onClick"=>"yesCouple()"),"Yes",$this->active));
insert($createTable, $createTable_r = button(array("name"=>"coupleNo","value"=>"No","onClick"=>"noCouple()"),"No",$this->active));
print "<script>function noCouple(){window.location='?m1=coursewareForms&m2=verifyInformation';}</script>";
print "<script>function yesCouple(){window.location='?m1=coursewareForms&m2=verifyInformation';}</script>";

I wanted to set the $_SESSION['skip'] = true if the "No" button was clicked. I just added &couple=no in my javascript and am checking if($rows != 0 && !$_GET['couple']). I don't know why I wasn't thinking along those lines to begin with.