Web/API/SubmitEvent

From Get docs

The SubmitEvent interface defines the object used to represent an HTML form's submit event. This event is fired at the <form> when the form's submit action is invoked.

Constructor

SubmitEvent()
Creates and returns a new SubmitEvent object whose type and other options are configured as specified. Note that currently the only valid type for a SubmitEvent is submit.

Properties

In addition to the properties listed below, this interface inherits the properties of its parent interface, Event.

submitter Read only
An HTMLElement object which identifies the button or other element which was invoked to trigger the form being submitted.

Methods

While SubmitEvent offers no methods of its own, it inherits any specified by its parent interface, Event.

Examples

In this example, a shopping cart may have an assortment of different submit buttons depending on factors such as the user's settings, the shop's settings, and any minimum or maximum shopping card totals established by the payment processors. Each of the submit elements' id is used to identify which payment processor the button corresponds to.

let form = document.querySelector("form");
form.addEventListener("submit", (event) => {
  let submitter = event.submitter;
  let handler = submitter.id;

  if (handler) {
    processOrder(form, handler);
  } else {
    showAlertMessage("An unknown or unaccepted payment type was selected. Please try again.", "OK");
  }
});

The handler ID is obtained by using the submit event's submitter property to get the submit button, from which we then get the ID. With that in hand, we can call a processOrder() function to handle the order, passing along the form and the handler ID.

Specifications

Specification Status Comment
HTML Living StandardThe definition of 'SubmitEvent' in that specification. Living Standard

Browser compatibility

Update compatibility data on GitHub

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
SubmitEvent Chrome

Full support 81

Edge

?

Firefox

Full support 75

IE

No support No

Opera

?

Safari

?

WebView Android

Full support 81

Chrome Android

Full support 81

Firefox Android

?

Opera Android

?

Safari iOS

?

Samsung Internet Android

Full support 13.0

SubmitEvent() constructor Chrome

Full support 81

Edge

?

Firefox

Full support 75

IE

No support No

Opera

?

Safari

?

WebView Android

Full support 81

Chrome Android

Full support 81

Firefox Android

?

Opera Android

?

Safari iOS

?

Samsung Internet Android

Full support 13.0

submitter Chrome

Full support 81

Edge

?

Firefox

Full support 75

IE

No support No

Opera

?

Safari

?

WebView Android

Full support 81

Chrome Android

Full support 81

Firefox Android

?

Opera Android

?

Safari iOS

?

Samsung Internet Android

Full support 13.0

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown