简体   繁体   English

将php变量发送到javascript中

[英]Send php variable into javascript

<input type="button" name="Next" id="Next" value="Next" onclick="showNextQuest(<?php echo $_POST  ['$qtnid']; ?>)" />

$qtnid is the name of a radio button, i used the post method to know which one among the radio buttons is selected. $ qtnid是单选按钮的名称,我使用post方法知道单选按钮中的哪个被选中。 The radio button has the same name with different values.It return an undefined error when itried to use alert function inside the showNextQuest function in the javascript. 单选按钮具有相同的名称和不同的值。当尝试在javascript的showNextQuest函数中使用警报功能时,它将返回未定义的错误。 plz help me out. 请帮我。

<input type="button" name="Next" id="Next" value="Next" onclick="showNextQuest(<?php echo $_POST  ['$qtnid']; ?>)" />

should be 应该

<input type="button" name="Next" id="Next" value="Next" onclick="showNextQuest('<?php echo $_POST  ['$qtnid']; ?>')" />

To make it a string, not a varname 使它成为字符串,而不是变量名

如果值是字符串,那么如果要将值作为字符串传递,则还应该在PHP周围加上单引号:

showNextQuest('<?php echo $_POST['$qtnid']; ?>')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM