title: How do I pass JavaScript variables to PHP?
body: <p>I want to pass JavaScript variables to PHP using a hidden input in a form.</p>
  
  <p>But I can't get the value of <code>$_POST['hidden1']</code> into <code>$salarieid</code>. Is there something wrong?</p>
  
  <p>Here is the code:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      // 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;
      }
  &lt;/script&gt;
  
  &lt;form name="myform" action="&lt;?php echo $_SERVER['$PHP_SELF']; ?&gt;" method="POST"&gt;
      &lt;input type="hidden" name="hidden1" id="hidden1" /&gt;
  &lt;/form&gt;
  
  &lt;?php
     $salarieid = $_POST['hidden1'];
     $query = "select * from salarie where salarieid = ".$salarieid;
     echo $query;
     $result = mysql_query($query);
  ?&gt;
  
  &lt;table&gt;
     Code for displaying the query result.
  &lt;/table&gt;
  </code></pre>