Skip to content Skip to sidebar Skip to footer

Onsubmit="return False" Has No Effect On Internet Explorer 7/8 (form Is Still Submitted)

I have a form that will be submitted by javascript code triggered in 'onsubmit' of the tag. Works fine on all browsers - but not on IE7/IE8. What can I do?
<formname="myform"><inputtype="submit" /></form><script>document.myform.onsubmit = function(){
    alert('handled');
    returnfalse;
  }
</script>

This can be made a lot simpler with jQuery, same form...

$("form[name=myform]").bind('submit',function(){
   alert('handled');
   returnfalse;
});

Solution 2:

Several ideas proposed here work (because they use different ways to write correct code), but there is a much easier answer

OP wrote :

onsubmit="submitmyform();"

instead of :

onsubmit="return submitmyform();"

That's it.

Solution 3:

I don't think your return false is ever reached, as it comes after what's returned from your function.

<formaction="/dosomething.htm"method="GET"onsubmit="submitmyform();return false">

Make sure that you return false inside of your 'submitmyform()' function else, if it's not then it could be returning true to you form obsubmit event.

Solution 4:

<scripttype="text/javascript">
<!--

functionsubmitHandler()
{
  alert(0);
  returnfalse;
}

window.onload=function(){document.getElementById("formid").attachEvent("onsubmit", submitHandler);}
-->
</script><formaction="/dosomething.htm"method="GET"id="formid">
  [...]
  <inputtype="submit"value="Go"></form>

The attach event method only works only for IE7/8. If you want a reliable cross browser solution you should use addEventListener as an alternative.

Hope it helps

Solution 5:

try this. work for me.

onSubmit="javascript:return false"

Post a Comment for "Onsubmit="return False" Has No Effect On Internet Explorer 7/8 (form Is Still Submitted)"