I have the following line of code:
<a href="javascript:;" onClick="tweeet('myid')">My Tweets!</a>
Now while this is working perfectly fine the following line is not:
<a href="javascript:;" onClick="tweeet(<?php echo 'myid'; ?>)">My Tweets!</a>
Can anyone help me out why it is not working and suggest any changes? The variable I want to pass to the Javascript function is a PHP variable. I have tried the PHP with single quotes and double quotes but it is not working.
You need quotes for both the php side and the Javascript side. You’ve only got php quotes there.
looks weird but it should work, though I’m no php expert. Note that if there’s any chance that “myid” (on the php side) might contain user-supplied data (like, something that came from an
<input>field at some time), or if it’s otherwise unpredictable, then it has to be put through something on the server side to make sure that the resulting tag is “clean”.