admin管理员组文章数量:1318156
How do I pass 2 PHP variables in a javascript function?
This one is working
echo '<button onClick = "count('.$increment.')">'.$counter.' </button>';
but when i do this
echo '<button onClick = "count('.$increment.','.$pass.')">'.$counter.' </button>';
it does not work, what is the problem?
By the way these are the variables:
$increment=5;
$pass="sdfgd";
How do I pass 2 PHP variables in a javascript function?
This one is working
echo '<button onClick = "count('.$increment.')">'.$counter.' </button>';
but when i do this
echo '<button onClick = "count('.$increment.','.$pass.')">'.$counter.' </button>';
it does not work, what is the problem?
By the way these are the variables:
$increment=5;
$pass="sdfgd";
Share
Improve this question
edited Feb 14, 2013 at 11:52
Tjoene
3509 silver badges18 bronze badges
asked Feb 14, 2013 at 11:28
Andre malupetAndre malupet
1113 silver badges12 bronze badges
0
4 Answers
Reset to default 4Try this dude......
<button onClick = "count('<?php echo $increment ?>','<?php echo $pass ?>')"><?php echo $counter ?></button>
echo '<button onClick = "count('.$increment.',\''.$pass.'\')">'.$counter.' </button>';
If $pass
contains exactly "sdfgd"
and with exactly I mean double quotes includes, this isn't a valid statement anymore, because your parser will find double quotes "too early" and them will close the onClick
event attribute
After variable expansion:
echo '<button onClick = "count('5','"sdfgd"')">'.$counter.' </button>';
-------------------------------------^
Take a look to the arrow
Edit
However, if you use a tool like firebug (if you run firefox), you can debug your code easily
The generated HTML code should look like this:
<button onClick = "count(5,sdfgd)">5 </button>
The variable sdfgd is most likely undefined, therefore undefined gets passed to your function.
If you want to pass a string you have to use quotes, so that the generated HTML looks like this:
<button onClick = "count(5,'sdfgd')">5 </button>
本文标签: How do I pass 2 PHP variables in a javascript functionStack Overflow
版权声明:本文标题:How do I pass 2 PHP variables in a javascript function? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742034086a2417006.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论