The HTMLFormElement method requestSubmit() requests that the form be submitted using a specific submit button.
On this page
HTMLFormElement: requestSubmit() method
Syntax
js
requestSubmit()
requestSubmit(submitter)
Parameters
submitterOptional-
A submit button that is a member of the form.
If the
submitterspecifiesform*attributes, they will override the form's submission behavior (e.g.formmethod="POST").If the
submitterhas anameattribute or is an<input type="image">, its data will be included in the form submission (e.g.btnName=btnValue).If you omit the
submitterparameter, the form element itself is used as the submitter.
Return value
None (undefined).
Exceptions
-
TypeError -
Thrown if the specified
submitteris not a submit button. NotFoundErrorDOMException-
Thrown if the specified
submitterisn't a member of the form on whichrequestSubmit()was called. The submitter must be either a descendant of the form element or must have aformattribute referring to the form.
Usage notes
The obvious question is: Why does this method exist, when we've had the submit() method since the dawn of time?
The answer is simple. submit() submits the form, but that's all it does. requestSubmit(), on the other hand, acts as if a submit button were clicked. The form's content is validated, and the form is submitted only if validation succeeds. Once the form has been submitted, the submit event is sent back to the form object.
Examples
In the example below, the form is submitted by attempting to send the request using requestSubmit() if it's available. If a submit button with the ID main-submit is found, that's used to submit the form. Otherwise, the form is submitted with no submitter parameter, so it's submitted directly by the form itself.
If, on the other hand, requestSubmit() isn't available, this code falls back to calling the form's submit() method.
js
let myForm = document.querySelector("form");
let submitButton = myForm.querySelector("#main-submit");
if (myForm.requestSubmit) {
if (submitButton) {
myForm.requestSubmit(submitButton);
} else {
myForm.requestSubmit();
}
} else {
myForm.submit();
}
Specifications
| Specification |
|---|
| HTML Standard # dom-form-requestsubmit-dev |
Browser compatibility
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
requestSubmit |
76 | 79 | 75 | No | 63 | 16 | 76 | 76 | 79 | 54 | 16 | 12.0 |
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/requestSubmit