Prevent a FORM SUBMIT with ENTERTag(s): Form

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

First technique (IE only)

function noenter() {
  return !(window.event && window.event.keyCode == 13);

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

Second method (works IE and FF)

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

blog comments powered by Disqus