HTMLFormElement: requestSubmit() method

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2022.

The HTMLFormElement method requestSubmit() requests that the form be submitted using a specific submit button.

Syntax

js
requestSubmit()
requestSubmit(submitter)

Parameters

submitter Optional

A submit button that is a member of the form.

If the submitter specifies form* attributes, they will override the form's submission behavior (e.g., formmethod="POST").

If the submitter has a name attribute or is an <input type="image">, its data will be included in the form submission (e.g., btnName=btnValue).

If you omit the submitter parameter, the form element itself is used as the submitter.

Return value

None (undefined).

Exceptions

TypeError

Thrown if the specified submitter is not a submit button.

NotFoundError DOMException

Thrown if the specified submitter isn't a member of the form on which requestSubmit() was called. The submitter must be either a descendant of the form element or must have a form attribute 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
# dom-form-requestsubmit-dev

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
requestSubmit()
Chrome – Full support
Chrome 76 (Release date: 2019-07-30)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 75 (Release date: 2020-04-07)
footnote Full support
Opera – Full support
Opera 63 (Release date: 2019-08-20)
footnote Full support
Safari – Full support
Safari 16 (Release date: 2022-09-12)
footnote Full support
Chrome Android – Full support
Chrome Android 76 (Release date: 2019-07-30)
footnote Full support
Firefox for Android – Full support
Firefox for Android 79 (Release date: 2020-07-28)
footnote Full support
Opera Android – Full support
Opera Android 54 (Release date: 2019-10-18)
footnote Full support
Safari on iOS – Full support
Safari on iOS 16 (Release date: 2022-09-12)
footnote Full support
Samsung Internet – Full support
Samsung Internet 12 (Release date: 2020-06-19)
footnote Full support
WebView Android – Full support
WebView Android 76 (Release date: 2019-07-30)
footnote Full support
WebView on iOS – Full support
WebView on iOS 16 (Release date: 2022-09-12)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support