Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/235.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/443.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将javascript变量作为php参数发送_Php_Javascript_Parameters - Fatal编程技术网

如何将javascript变量作为php参数发送

如何将javascript变量作为php参数发送,php,javascript,parameters,Php,Javascript,Parameters,嗨,我有一个javascript函数,它可以打开一个弹出窗口,并在其中打开一个php文件,但我甚至想发送一个参数,但它不起作用。参数作为变量名而不是其值发送 这是我的剧本 <?php if($addflag == 0){ echo " <script type=\"text/javascript\"> function mopen(){ var mobj=document.getElementById('dtype').value; //// t

嗨,我有一个javascript函数,它可以打开一个弹出窗口,并在其中打开一个php文件,但我甚至想发送一个参数,但它不起作用。参数作为变量名而不是其值发送 这是我的剧本

             <?php 

 if($addflag == 0){
echo "
<script type=\"text/javascript\">
function mopen(){
var mobj=document.getElementById('dtype').value; //// this variable is shown as a name instead of its value
window.open('quotprin.php?vouchno=' . urlencode($getvouch) . '&dtype=mobj','popUpWindow','height=800,width=950,left=100,top=100,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no, status=yes');
}
</script>
";

echo "<td>";
echo '<font color="red">Print On Letter Head</font>
<input type="checkbox" id="dtype" name="dtype" value="1" checked="checked" />';
echo '<input class="cmdprint" type="button" id="submit" name="print" value="Print" onclick="mopen();"></td>';
echo "<td>";
}
            ?>

这不完全是您的原始代码,但它可以正常工作。您有太多的转义斜杠和单引号或双引号。要找出这样的错误可能太令人困惑了

<?php 

$getvouch = isset($_GET['getvouch'])? $_GET['getvouch'] : null;

?>

    <script type="text/javascript">
    function mopen(){
       var mobj=document.getElementById('dtype').value;
       var url="quotprin.php?vouchno=<?php echo $getvouch; ?>&dtype="+ mobj;
       window.open(url,'popUpWindow','height=800,width=950,left=100,top=100,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no, status=yes');
    }
    </script>

    <table><tr><td>
    <font color="red">Print On Letter Head</font>
    <input type="checkbox" id="dtype" name="dtype" value="1" checked="checked" />
    <input class="cmdprint" type="button" id="submit" name="print" value="Print" onclick="mopen();"></td>
    </tr></table>

函数mopen(){
var mobj=document.getElementById('dtype').value;
var url=“quotprin.php?vouchno=”dtype=“+mobj;
打开(url,'popUpWindow','height=800,width=950,left=100,top=100,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,Directory=no,status=yes');
}
印在信头上
这里最重要的是查看如何将“getvouch”变量添加到getmobi url

如果使用此url:add-a-javascript-var-and-send-it-with-post.php?getvouch=6

获取mobi链接到:quotprin.php?vouchno=6&dtype=mobj

如果不是这个问题,请解释得更清楚一点

更新。 现在我看到的错误是您没有在url中转义mobj变量。尝试更改。

尝试以下操作:
try this:      
<?php 

if($addflag == 0){
$getvouch = urlencode($getvouch);
echo "
<script type=\"text/javascript\">
function mopen(){
var mobj=document.getElementById('dtype').value; //// this variable is shown as a name     instead of its value
window.open('quotprin.php?vouchno=    {$getvouch}&dtype=mobj','popUpWindow','height=800,width=950,left=100,top=100,resizable=yes,    scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no, status=yes');
}
</script>
";

echo "<td>";
echo '<font color="red">Print On Letter Head</font>
<input type="checkbox" id="dtype" name="dtype" value="1" checked="checked" />';
echo '<input class="cmdprint" type="button" id="submit" name="print" value="Print"     onclick="mopen();"></td>';
echo "<td>";
}
          ?>

给出更多代码,$getvouch包含什么?也许格式不好,你逃过了吗?更改此vouchno='$“给你。”&数据类型为vouchno='。urlencode($getvouch)。'&DTypesr问题不在于mobj而在于getvouch,但感谢您的建议。问题不在于$getvouch,而在于javascript变量mobjth mobj发送的是它的名称,而不是它的值,该值应为0或1。请查看代码中的更改。它在url变量中使用$getvouch和mobj的值。