Submission is one algorithm in the HTML standard, run in a fixed order:
- A trigger and a submitter. Clicking a submit button, pressing Enter in a text field (implicit submission),
form.requestSubmit(button), orform.submit(). The button that caused it is the submitter; with no button, it's the form itself. - Validation. Unless the form has
novalidateor the submitter hasformnovalidate, the browser checks the constraints. If any control is invalid it reports it and stops. - The
submitevent. It bubbles, is cancelable, and carriesevent.submitter.preventDefault()here is how script takes over. - The entry list. Every submittable element owned by the form, in tree order, except controls that are disabled, have no
name(or an empty one), are unchecked checkboxes or radios, or are buttons other than the submitter. A checkbox with novaluesendson; aselectsends each selected option. Aformdataevent then lets script add entries. - Encoding.
methoddefaults to GET: the entries are serialised asapplication/x-www-form-urlencodedand replace the query ofaction. POST sends them as the body, encoded byenctype:application/x-www-form-urlencoded(default),multipart/form-data, ortext/plain. Only multipart sends file contents; the other two send just the file name.method="dialog"sends nothing and closes the enclosing<dialog>. - Navigation. The browser navigates
target(default: this page) toaction, which defaults to the document's URL. The page is replaced by the response.
form.submit() runs only steps 4–6: no validation and no submit event, so your handlers don't run. form.requestSubmit(submitter) runs everything, exactly like a click, and throws a TypeError if the argument isn't a submit button. Use requestSubmit() when script needs to submit.