Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

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

You are here: irt.org | FAQ | JavaScript | Form | Q1279 [ previous next ]

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?'

©2018 Martin Webb