
Take the following example: ĭocument.getElementById('name').If you have problems printing text boxes, go to File > Options > Display and under Printing Options, select Print drawings created in Word. Explicit Preventionįinally, it’s also quite easy to prevent implicit submission in JavaScript. Most screen readers have a mode specifically for filling out forms, and by omitting a true tag you risk this mode not being activated. However, much like implicit submission, surrounding form data with a true tag is vital for accessibility. Because an AJAX request does not require a true tag, it is often omitted. With modern day browsers and JavaScript libraries it’s easy to send data to the server via AJAX. I’ve seen a few forms that do not use the HTML tag. If you need to run some JavaScript before the form is submitted (validation, data manipulation, etc), do it in a submit event handler on the form, not a click handler on a button.

Therefore for IE7 compatibility you’ll need. (Note: IE7 has a bug where the type attribute of a defaults to button instead of submit. Specifically an with the type="submit" attribute, or a element should be present. Therefore, if you have a form with more than one input field, always include a submit button. Therefore, pressing enter in this textbox will submit the form: īut in this form it will not because there are multiple fields:

So, in a form with no submit buttons, implicit submission will be done if only one input is present. “If the form has no submit button, then the implicit submission mechanism must do nothing if the form has more than one field that blocks implicit submission, and must submit the form element from the form element itself otherwise.įor the purpose of the previous paragraph, an element is a field that blocks implicit submission of a form element if it is an input element whose form owner is that form element and whose type attribute is in one of the following states: Text, Search, URL, Telephone, E-mail, Password, Date and Time, Date, Month, Week, Time, Local Date and Time, Number” “If the user agent supports letting the user submit a form implicitly (for example, on some platforms hitting the “enter” key while a text field is focused implicitly submits the form), then doing so for a form whose default button has a defined activation behavior must cause the user agent to run synthetic click activation steps on that default button.”īasically, if the user hits enter when a text field is focused, the browser should find the first submit button in the form and click it. From the spec here’s how browsers determine what to do when enter is clicked. Many sites do not have a submit button within the form. What are sites doing to keep this from happening? Here’s a few things I’ve seen. Interfering with this leads to a negative user experience for these users. Many users have an expectation that implicit submission will just work. The spec strongly encourages browsers to allow implicit submission they all do. “There are pages on the Web that are only usable if there is a way to implicitly submit forms, so user agents are strongly encouraged to support this.” Implicit submission is vital to assistive technologies and impaired users that cannot use a mouse at all. This behavior is consistent across all browsers and is known as implicit submission. If you have focus in the textbox and hit enter, the form will be submitted automatically. Before I tell you why you care, let’s look at how this should work. In the course of my internet-ing there’s one unfortunate trend that I’ve noticed an increasing number of sites are not allowing the enter key to submit a form. I try to do most of my work and play on the internet with the keyboard.
