Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jul 2006
    Location
    Cincinnati, OH
    Posts
    85
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Can you assign a php variable a value using JS?

    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?

  • #2
    New Coder
    Join Date
    May 2006
    Posts
    56
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Explain better what u wanna do

  • #3
    New Coder
    Join Date
    May 2006
    Posts
    56
    Thanks
    0
    Thanked 0 Times in 0 Posts
    try like this:

    PHP Code:
    <?
    if (isset($_REQUEST['SessionString'])){
      
    $_SESSION['SomeString']=$_REQUEST['SessionString'];
    }
    ?>
    Code:
    <input type='button' onClick="location.href='mypage.php?SessionString=somevalue'" />

  • #4
    New Coder
    Join Date
    Jul 2006
    Location
    Cincinnati, OH
    Posts
    85
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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:

    PHP Code:
    if($rows != && $_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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •