<form method="POST" action="">
<input type="text" />
<input type="text" />
</form>
(JSFiddle)
Press enter on the input
. Then delete one of the input
s and press it again. When we have two inputs inside of the form, the form is not submitted (we need a button then). Why is that?
The default behavior of HTML forms with a single input is to submit on enter. As soon as you add a second input, pressing enter will no longer submit the form. The presense or lack of names has nothing to do with it.
The original idea was that very simple forms, typically consisting just of a text input box e.g. for searching, should be easy and quick: the user just types a search word and hits Enter. Controls of other types, such as checkboxes, do not affect this. Virtually all browsers implemented this idea.
But, according to the old idea, if there are several text input boxes, there are too big risks of premature form submission: the user hits Enter, expecting to get to the next field, or maybe just by accident.
Yet, IE introduced (in IE 4) the feature that makes Enter in a text input box submit the form, even if the form contains several such elements. Later, other browsers followed suit, and nowadays this (mis?)behavior appears to be “standard.” This feature has been claimed to be an usability improvement, and in some special cases, it really is. More often, it is a risk, and therefore pages often try to use client-side scripting to prevent it.
However, at least on most modern browsers, this only happens when the form has a submit button. But if you omit the submit button, users will get puzzled, as most forms have a submit button or buttons.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With