Passing javascript variable to php

I want to pass JavaScript variables to PHP using a hidden input in a form.

But I can't get the value of $_POST['hidden1'] into $salarieid. Is there something wrong?

Here is the code:


    // View what the user has chosen
    function func_load3[name] {
        var oForm = document.forms["myform"];
        var oSelectBox = oForm.select3;
        var iChoice = oSelectBox.selectedIndex;
        //alert["You have chosen: " + oSelectBox.options[iChoice].text];
        //document.write[oSelectBox.options[iChoice].text];
        var sa = oSelectBox.options[iChoice].text;
        document.getElementById["hidden1"].value = sa;
    }





   Code for displaying the query result.

asked Dec 16, 2009 at 20:46

SUN JiangongSUN Jiangong

5,11216 gold badges56 silver badges76 bronze badges

2

You cannot pass variable values from the current page JavaScript code to the current page PHP code... PHP code runs at the server side, and it doesn't know anything about what is going on on the client side.

You need to pass variables to PHP code from the HTML form using another mechanism, such as submitting the form using the GET or POST methods.



  
    My Test Form
  

  
    
      

Please, choose the salary id to proceed result:

SalarieID:

Chủ Đề