Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a standard resource for the "default action" of HTML elements? [closed]

I'm wondering if there is a defined standard for what the default action is of various HTML elements. I've looked at the W3C's HTML specification and while they are very precise with what attributes can be used with elements (and also some behavioural stuff such as exactly what gets included with form submission) there's nothing about the behaviour of elements. I've also checked out the Mozilla JS reference, and found nothing there either.

In particular I'm looking for the default behaviour of a form submit button; I've seen in different places that its default action is to submit the form and alternatively that its default action is not to submit the form but rather to get focus. Accordingly, there seems to be no consensus on whether onclick="return false;" for a submit button will stop form submission or not.

(Edit for clarity - I'm not trying to do any form-level validation on the submit's onclick or anything like that; if I were, I'd be using the form's onsubmit instead. I really am specifically interested in catching clicks on the button and potentially not having it submit the form in this case. This might end up requiring the button's onclick set some state that the form's onsubmit inspects, but if I can just return false then that's great. Even if not, it would then be critical what order the onsubmit and onclick handlers get fired (i.e. does the button dispatch the submit before running its click handler?) which again I haven't seen specified anywhere.)

While it would be simply to code up a test, I'd rather rely on specs/documented behaviour rather than the results of a trivial test that would undoubtedly miss any subtleties should they exist. In particular, I ran a quick test last week that seemed to show it didn't stop form submission, but running one today shows that it does. I have had no luck finding any sort of authoritative resource as to what browsers actually do when you interact with their elements (e.g. what the default action is, whether the onclick handler for a submit button fires before or after the form submission dispatch, etc.)

Any advice as to where to look in this case would be welcome.

like image 450
Andrzej Doyle Avatar asked Nov 15 '22 16:11

Andrzej Doyle


1 Answers

The relevant documents are DOM3 Events and the HTML 5 specification.

They might not have all information you need, but should. So if you find them lacking, please request those behaviors to be specified.

like image 85
Kornel Avatar answered Dec 22 '22 13:12

Kornel