docs:browsers:prevent_enter_from_submitting_forms

The enter key seems to submit a form if a user enters in a text field and presses enter. I think it actually finds the first action button/element in the form instead of actually submitting the form as if the “submit” button was clicked. This was found when two input elements of type “image” were being used for Cancel and Submit. The cancel button was before the submit button, so any time the user pressed enter in a text field, the form was cancelled instead of submitted.

If you can assume javascript, you can add this to the form tag:

onsubmit="return false;"

…and then allow the form to be submitted when the submit button is clicked by using the onclick event.

  • docs/browsers/prevent_enter_from_submitting_forms.txt
  • Last modified: 2009/06/05 17:13
  • by billh