admin管理员组文章数量:1336660
I am running the < a > tag in php. Whenever I pass an argument in js function it does not get called but if i pass empty arguments, the function gets called.
js:
function displayBigImage(img){
alert("inside func");
}
php:
//NOT WORKING:
echo "<a href='javascript:displayBigImage('".$row['IMG_ID']."')'>Press</a>";
//WORKING:
echo "<a href='javascript:displayBigImage()'>Press</a>";
I also tried with harcode argument values like,
echo "<a href='javascript:displayBigImage('sample.jpg')'>Press</a>";
or
echo "<a href='javascript:displayBigImage(sample.jpg)'>Press</a>";
I don't understand whats wrong?!?!?!?!
PLease reply asap.
Thanks in advance
I am running the < a > tag in php. Whenever I pass an argument in js function it does not get called but if i pass empty arguments, the function gets called.
js:
function displayBigImage(img){
alert("inside func");
}
php:
//NOT WORKING:
echo "<a href='javascript:displayBigImage('".$row['IMG_ID']."')'>Press</a>";
//WORKING:
echo "<a href='javascript:displayBigImage()'>Press</a>";
I also tried with harcode argument values like,
echo "<a href='javascript:displayBigImage('sample.jpg')'>Press</a>";
or
echo "<a href='javascript:displayBigImage(sample.jpg)'>Press</a>";
I don't understand whats wrong?!?!?!?!
PLease reply asap.
Thanks in advance
Share Improve this question edited Aug 22, 2009 at 21:43 Gumbo 656k112 gold badges791 silver badges851 bronze badges asked Aug 22, 2009 at 21:39 sbsb3 Answers
Reset to default 8You have problems with your quoting:
<a href='javascript:displayBigImage('sample.jpg')'>
You can't use single quotes both around the HTML attribute and within it. You need to use different quotes in the two places, for instance:
<a href="javascript:displayBigImage('sample.jpg')">
So in your PHP, that bees:
echo "<a href=\"javascript:displayBigImage('".$row['IMG_ID']."')\">Press</a>";
You have some mismatched quote marks. Where you have this:
echo " < a href='javascript:displayBigImage('".$row['IMG_ID']."')'>Press< / a >";
You should have this:
echo " <a href=\"javascript:displayBigImage('" . $row['IMG_ID'] . "')\">Press</a>";
If you’re using single quotes for the HTML attribute value declaration, you can’t use the same quotes inside the attribute values without describing them by character references.
So you either use the double quotes inside your href
attribute value:
echo "<a href='javascript:displayBigImage(\"".$row['IMG_ID']."\")'>Press</a>";
Or you use proper character references:
echo "<a href='javascript:displayBigImage(".$row['IMG_ID'].")'>Press</a>";
Or you use the double quotes for the href
attribute value declaration:
echo "<a href=\"javascript:displayBigImage('".$row['IMG_ID']."')\">Press</a>";
本文标签: javascript function not get called when arguments from phpStack Overflow
版权声明:本文标题:javascript function not get called when arguments from php - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742421442a2471736.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论