THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

onsubmit Event

Event Object Reference Event Object

Example

Execute a JavaScript when a form is submitted:

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

Definition and Usage

The onsubmit event occurs when a form is submitted.


Browser Support

Event
onsubmit Yes Yes Yes Yes Yes

Syntax

In HTML:

<element onsubmit="myScript">Try it

In JavaScript:

object.onsubmit=function(){myScript};Try it

In JavaScript, using the addEventListener() method:

object.addEventListener("submit", myScript);Try it

Note: The addEventListener() method is not supported in Internet Explorer 8 and earlier versions.


Technical Details

Bubbles: Yes
Cancelable: Yes
Event type: Event
Supported HTML tags: <form>, <keygen>
DOM Version: Level 2 Events

Event Object Reference Event Object