Reputation: 151
i am working on javascript onclick event, when i call function on button click it not gets works on IE browsers (IE-9 & IE-8)
code as following
<input type='image' src="mybutton.jpeg" name="submit" id="button" onclick="return myfunction();" />
i have defined function at top of my page,
<script type="text/javascript">
function myfunction()
{
alert("This is testing");
}
</script>
Working on all other browsers like chrome & firefox but not in IE.
Please help me on this.
Upvotes: 0
Views: 3582
Reputation: 3355
I don't like putting "listener" attributes. This works for me:
HTML:
<input type='image' src="" name="submit" id="button" />
JS:
function myfunction() {
alert("This is testing");
}
document.getElementById('button').addEventListener('click', function() {
return myfunction()
} , false);
Upvotes: 0
Reputation: 68596
Change your onclick from:
onclick="return myfunction();"
to
onsubmit="return myfunction();"
Upvotes: 1