Mark Martin
Mark Martin

Reputation: 151

Javascript function is not working in IE browser

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

Answers (2)

Jeff Shaver
Jeff Shaver

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

dsgriffin
dsgriffin

Reputation: 68596

Change your onclick from:

onclick="return myfunction();"

to

onsubmit="return myfunction();"

Upvotes: 1

Related Questions