0
<button class="addToPlaylist" onclick="javascript:myPopup(<?php echo $videos[$counter]?>);
return false;">+</button>

I have a button on an image as a html hyperlink. I want to perform different actions on hyperlink and button. The above code works whenever I do not pass the PHP variable using echo. When i pass PHP variable, the button also performs the same action as of the hyperlink, that means return false does not work.

Any idea why the return false; does not work when i pass PHP variable?

2
  • 2
    Check the HTML source, see what PHP has generated. Commented Jan 16, 2012 at 17:11
  • 1
    Is $videos[$counter] a string? If so, you need quotes around it... Commented Jan 16, 2012 at 17:12

3 Answers 3

2

This should be:

<button class="addToPlaylist" onclick="javascript:myPopup('<?php echo $videos[$counter];?>');return false;">+</button>

Note the single quotes in myPopup. As you pass a string to myPopup, you will need to enclose it with single quotes. (Double won't work as there is already double quotes for the onclick)

1

I am quite sure $videos[$counter] is not numeric, but a string. In this case you have to write the quotes:

onclick="javascript:myPopup('<?php echo $videos[$counter]?>');

And make sure, $videos[$counter] doesn't contain any, something like

onclick="javascript:myPopup('<?php echo addslashes($videos[$counter])?>');

comes to mind.

0
0

onclick="javascript:myPopup("";return false;" . This should work and i think it's more clear where you have javascript code and php code.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.