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?
<form action="/dosomething.htm" method="GET" onsubmit="submitmyform();return false">
[...]
<input type="submit" value="Go">
</form>
It means that do nothing on submit.
The onsubmit property of a Form object specifies an event handler function that is invoked when the user submits a form by clicking on a Submit button in the form. Note that this event handler is not invoked when the Form.
I'm going to nitpick this. If you want to handle form submissions, that is what submit is for. If the user hits enter in one of your fields, your onclick handler will be totally avoided. Here is a basic example of doing this in a non-obtrusive way.
<form name="myform">
<input type="submit" />
</form>
<script>
document.myform.onsubmit = function(){
alert('handled');
return false;
}
</script>
This can be made a lot simpler with jQuery, same form...
$("form[name=myform]").bind('submit',function(){
alert('handled');
return false;
});
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With