DOM HTMLFormElement: submit event
The submit event fires when a form is submitted, by a submit button, pressing Enter or requestSubmit(). It's the place to validate or send form data with JavaScript.
Description
The submit event fires on a <form> when it is submitted: by clicking a submit button, pressing Enter in a field, or calling requestSubmit(). It fires after the browser's built-in validation passes. Call event.preventDefault() to stop the page from navigating, then handle the data yourself, typically with new FormData(form) and fetch().
Listen for submit on the form rather than click on the button, so keyboard submission is handled too. event.submitter tells you which button was used. Calling form.submit() directly skips both validation and this event.
The submit event bubbles, so a listener on the document can handle every form on a page. If the browser's validation fails, the event doesn't fire and the browser shows its error messages instead; add novalidate to the form to handle validation yourself.
Syntax
form.addEventListener('submit', handler)Example
Browser Support
The following information will show you the current browser support for the HTMLFormElement: submit event event. Hover over a browser icon to see the version that first introduced support for this event.
Desktop





Tablets & Mobile





