onsubmit Event
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 JavaScript, using the addEventListener() method:
object.addEventListener("submit", myScript);
Try it Yourself »
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