Reputation: 31
echo '<a onclick="alert(\'alert\');"><img src= "1.jpeg"></a>';
It is working fine, But
echo '<a onclick="do();"><img src= "1.jpeg"></a>';
Its not working if i put that alert inside do() like
<script type="text/javascript">
function do()
{
alert("alert");
}
</script>
Can any body help on this.
Upvotes: 0
Views: 2288
Reputation: 671
You can't have a function named do(). Change the name to something else. Also, it would be a good idea to use something like:
echo '<a href="javascript:void(0)" onclick="your_function();return false;">
<img src="img.jpg">
</a>';
Upvotes: 1
Reputation: 1162
do
is a reserved word in javascript. Try naming the method something else.
Upvotes: 1