Reputation: 72709
What does the HTML spec say about using enter key to submit a form?
I've read http://www.w3.org/TR/html4/interact/forms.html but nothing there about submitting a form using the enter key.
Is it even defined somewhere or is it just the way most browsers have implemented it on their own and it became the way to do it
?
I'm curious because I just asked a question regarding Webkit not submitting my form if the submit button is hidden (display: none
).
Trying to 'submit' my form when hitting enter fails
So is there somewhere in the official docs a reference to the behavior of the enter key in a form?
Upvotes: 0
Views: 712
Reputation: 514
I know this question is old but I just had the same issue with webkit browsers. I found if you use visibility: hidden
in lieu of display: none
the enter button will submit the form. I know this adds a few more styling challenges but it essentially accomplishes the task. As far as the standard goes, it's been over a year and I failed to find anything more informative than phihag's answer.
Upvotes: 1
Reputation: 33379
The spec says that all forms are required to have an action
attribute. If you have one of these, the enter key will work. I've got forms with no submit button at all, and the enter key is functional.
You can attach javascript to the submit event, which could prevent the browser from navigating to the action uri.
But whatever you do, you are required to have an action
uri, and it should be functional.
Upvotes: -1
Reputation: 288260
The HTML standard is device-agnostic; HTML user agents run on a variety of platforms, many of which (think search engine, voice reader, webscraper) do not have a keyboard in the first place. Therefore, the standard does not say how a user can toggle the form submission. Listing all possible ways to submit a form is impossible, since many devices and user interaction mechanisms are not invited yet - iOS 6 may allow you to submit a form by saying "Submit Form!".
The Webkit behavior you're seeing is up to the discretion of Webkit and likely unintentional. The standard does not say anything about a submit button being necessary in the submission process.
Upvotes: 2
Reputation: 23999
It's not part of the spec. It's something that the browser makers implement at their discretion.
Upvotes: 1