onsubmit event
Example
Execute JavaScript when the form is submitted:
<form action="demo-form.php" onsubmit="myFunction()">Enter name:
<input type="text" name="fname">
<input type="submit" value="Submit" form>Try it »
Definition and Usage
The onsubmit event is triggered when the form is submitted.
Browser support
| Events | |||||
|---|---|---|---|---|---|
| onsubmit | Yes | Yes | Yes | Yes | Yes |
Syntax
In HTML:
<
element
onsubmit="
myScript
">Try it
In JavaScript:
object
.onsubmit=function(){
myScript
};
Try it
In JavaScript, use the addEventListener() method:
object
.addEventListener("submit",
myScript
);
Try it
Note: Internet Explorer 8 and earlier IE versions do not support addEventListener() method.
Technical Details
| Does it support bubbling: | Yes |
|---|---|
| Is it cancelable: | No |
| Event type: | Event |
| Supported HTML tags: |
Event Object