Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q1279 How to restrain a form from being submitted with the Enter key?

irt.org | Knowledge Base | JavaScript | Form | Q1279 [ previous next ]

Q1279 How to restrain a form from being submitted with the Enter key?

Block the submit behaviour in the form, and activate it with the onClick handler:

Javascript code
<script language="javascript">
function submitForm ()
{
  document.myForm.onsubmit = function onSubmit(event) { return true; };
  // note that the 1st onsubmit is all in lowercase
}
</script>

Form code
<form name="myForm" method=post action="/foo/bar.pm" onSubmit="return false;">
<input type="text" name="some_text">
<input type="submit" value="Submit" onClick="submitForm()">
</form>

Submitted by Frederic Hurtubise

Feedback on 'Q1279 How to restrain a form from being submitted with the Enter key?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.