Prevent a FORM SUBMIT with ENTERTag(s): Form


To submit the form only when user click the SUBMIT button.

First technique (IE only)

<script>
function noenter() {
  return !(window.event && window.event.keyCode == 13);
}
</script>

<form name="myform1" action="http://ww.google.ca">
text1:<input type=text onKeyPress="return noenter()">
text2:<input type=text onKeyPress="return noenter()">
<input type=submit value="GO">
</form>
Try it (IE only):
text1: text2:

Second method (works IE and FF)

<form name="myform2" action="http://ww.google.ca" onSubmit="return false">
text1:<input type=text >
text2:<input type=text >
<input type=button value="GO" onClick="document.myform2.submit()">
</form>
Try it (works IE and FF):
text1: text2:

blog comments powered by Disqus