onsubmit event

Definition and Usage

The onsubmit event occurs when the form is submitted.

Example

Execute JavaScript when submitting the form:

<form onsubmit="myFunction()">
  Enter name: <input type="text">
  <input type="submit">
</form>

Try it yourself

Syntax

In HTML:

<element onsubmit="myScript">

Try it yourself

In JavaScript:

object.onsubmit = function(){myScript};

Try it yourself

In JavaScript, use the addEventListener() method:

object.addEventListener("submit", myScript);

Try it yourself

Note:Internet Explorer 8 or earlier versions do not support Méthode addEventListener().

Détails techniques

Bubbling : Support
Annulable : Support
Type d'événement : Event
Balises HTML prises en charge : <form>
Version DOM : Événements de niveau 2

Support du navigateur

Événements Chrome IE Firefox Safari Opera
onsubmit Support Support Support Support Support