相关疑难解决方法(0)

如何将JavaScript变量传递给PHP?

我想使用表单中的隐藏输入将JavaScript变量传递给PHP.

但我不能得到的价值$_POST['hidden1']$salarieid.有什么不对?

这是代码:

<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);
?> …
Run Code Online (Sandbox Code Playgroud)

javascript php variables

136
推荐指数
9
解决办法
50万
查看次数

如何将JavaScript变量用作PHP变量?

我试图将PHP变量作为PHP变量包含在PHP代码中,但我遇到了这样的问题.单击按钮时,将调用以下函数:

<script type="text/javascript">
    function addTraining(leve, name, date)
    {
        var level_var = document.getElementById(leve);
        var training_name_var = document.getElementById(name);
        var training_date_var = document.getElementById(date);

        <?php
            $result = "INSERT INTO training(level, school_name, training_date) VALUES('level_var', 'training_name_var', 'training_date_var')" or die("Query not possible.");
        ?>

</script>
Run Code Online (Sandbox Code Playgroud)

可能吗?

javascript php

19
推荐指数
3
解决办法
18万
查看次数

标签 统计

javascript ×2

php ×2

variables ×1