如何将 JavaScript 变量传递给 PHP? - How do I pass JavaScript variables to PHP?

问题:

I want to pass JavaScript variables to PHP using a hidden input in a form.我想使用表单中的隐藏输入将 JavaScript 变量传递给 PHP。

But I can't get the value of $_POST['hidden1'] into $salarieid .但是我无法将$_POST['hidden1']转换为$salarieid Is there something wrong?有什么不对?

Here is the code:这是代码:

<script type="text/javascript">
    // 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;
    }
</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 * from salarie where salarieid = ".$salarieid;
   echo $query;
   $result = mysql_query($query);
?>

<table>
   Code for displaying the query result.
</table>

解决方案:

参考一: https://en.stackoom.com/question/82qe
参考二: https://stackoom.com/question/82qe
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章