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 addEventListener() Method.

Technical Details

Bubble: Support
Cancelable: Support
Event Type: Event
Supported HTML Tags: <form>
DOM Version: Level 2 Events

Browser Support

Events Chrome IE Firefox Safari Opera
onsubmit Support Support Support Support Support