Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are forms not submitted if there is more than one unnamed input?

Tags:

html

forms

<form method="POST" action="">
    <input type="text" />
    <input type="text" />
</form>

(JSFiddle)

Press enter on the input. Then delete one of the inputs 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?

like image 959
good_evening Avatar asked Dec 11 '11 05:12

good_evening


2 Answers

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.

like image 77
Brandon Gano Avatar answered Nov 18 '22 17:11

Brandon Gano


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.

like image 30
Jukka K. Korpela Avatar answered Nov 18 '22 17:11

Jukka K. Korpela