You are here: irt.org | FAQ | JavaScript | Form | 7.1 | Q1179 [ previous next ]
Try:
<script language="JavaScript"><!-- if (document.layers) document.captureEvents(Event.KEYPRESS); window.onkeypress = keyhandler; function keyhandler(e) { var event = e ? e : window.event; if (event.keyCode == 13) return false; } //--></script> <form name="myForm" onSubmit="alert('submitted'); return false;"> <input type="text" name="field1" onKeyPress="keyhander(e)"> <input type="text" name="field2" onKeyPress="keyhander(e)"> </form>
The following was submitted by Jonno Smith
This is apparently a 'feature' of IE. The simplest workaround I have found is not to use a submit button. Instead, provide an onclick method for a normal button. For all intents and purposes, this looks and works just like an ordinary form, but does not submit when the enter key is pressed.
<SCRIPT LANGUAGE="JavaScript"><!-- function doButtonMethod() { form1.submit(); } //--></SCRIPT> <INPUT TYPE="TEXT> <INPUT TYPE="button" onclick="doButtonMethod();" value="Submit Form">
The following was submitted by Pawe³ Piejko
Instead of:
<input type="submit" name="Submit">
We can use:
<input type="button" value="Submit" onClick="JavaScript:document.name_form.submit();">