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?

GameAlchemist
  • 18,995
  • 7
  • 36
  • 59

3 Answers3

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)

jValdron
  • 3,408
  • 1
  • 28
  • 44
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.

Eugen Rieck
  • 64,175
  • 10
  • 70
  • 92
0

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

anjalis
  • 397
  • 2
  • 19