How to pass JavaScript variables to PHP? -


i want pass javascript variables php using hidden input in form.

but can't value of $_post['hidden1'] $salarieid. there wrong?

here code:

<script type="text/javascript"> // view user has chosen function func_load3(name){     var oform = document.forms["myform"];     var oselectbox = oform.select3;     var ichoice = oselectbox.selectedindex;     //alert("you have choosen: " + oselectbox.options[ichoice].text );     //document.write(oselectbox.options[ichoice].text);     var sa = oselectbox.options[ichoice].text;     document.getelementbyid("hidden1").value = sa; } </script>  <form name="myform" action="<?php echo $_server['$php_self']; ?>" method="post">         <input type="hidden" name="hidden1" id="hidden1"  /> </form>  <?php    $salarieid = $_post['hidden1'];    $query = "select * salarie salarieid = ".$salarieid;    echo $query;    $result = mysql_query($query); ?>  <table>    code display query result.  </table> 

you cannot pass variable values current page javascript current page php code... php code runs @ server side , doesn't know going on on client side.

you need pass variables php code html-form using mechanism, such submitting form on or post methods.

<doctype html> <html>   <head>     <title>my test form</title>   </head>    <body>     <form method="post">       <p>please, choose salary id proceed result:</p>       <p>         <label for="salarieids">salarieid:</label>         <?php           $query = "select * salarie";           $result = mysql_query($query);           if ($result) :         ?>         <select id="salarieids" name="salarieid">           <?php             while ($row = mysql_fetch_assoc($result)) {               echo '<option value="', $row['salaried'], '">', $row['salaried'], '</option>'; //between <option></option> tags can output more human-friendly (like $row['name'], if table "salaried" have one)              }           ?>         </select>         <?php endif ?>       </p>       <p>         <input type="submit" value="sumbit choice"/>       </p>     </form>      <?php if isset($_post['salaried']) : ?>       <?php         $query = "select * salarie salarieid = " . $_post['salarieid'];         $result = mysql_query($query);         if ($result) :       ?>         <table>           <?php             while ($row = mysql_fetch_assoc($result)) {               echo '<tr>';               echo '<td>', $row['salaried'], '</td><td>', $row['bla-bla-bla'], '</td>' ...; // , others               echo '</tr>';             }           ?>         </table>       <?php endif?>     <?php endif ?>   </body> </html> 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -