onresetEvent
Example
Execute JavaScript when the form is reset:
<form onreset="myFunction()">
Enter name: <input type="text">
<input type="reset">
</form>
Enter name: <input type="text">
<input type="reset">
</form>
Try it yourself »
Definition and Usage
The onreset event is triggered after the form is reset.
Browser Support
| Event | |||||
|---|---|---|---|---|---|
| onreset | Yes | Yes | Yes | Yes | Yes |
Syntax
In HTML:
<element onreset="myScript">Try it yourself
In JavaScript:
object.onreset=function(){myScript};Try it yourself
In JavaScript, using the addEventListener() method:
object.addEventListener("reset", myScript);Try it yourself
Note:Internet Explorer 8 and earlier IE versions do not supportaddEventListener()method.
Technical Details
| Bubbles: | Yes |
|---|---|
| Cancelable: | Yes |
| Event type: | Event |
| Supported HTML tags: | <form>, <keygen> |
More Examples
Example
Display the content written in the text field before the form is reset:
var x = document.getElementById("myInput");
alert("Before reset, the text content is: " + x.value);
alert("Before reset, the text content is: " + x.value);
Try it yourself »
Example
Use the reset() method of the HTML DOM Form Object to reset the form. When executed, the onreset event is triggered and an alert message will pop up.
// Reset all element values of the form with id="myForm"
function myResetFunction() {
document.getElementById("myForm").reset();
}
// Display a prompt message after the form is reset
function myAlertFunction() {
alert("Form has been reset");
}
function myResetFunction() {
document.getElementById("myForm").reset();
}
// Display a prompt message after the form is reset
function myAlertFunction() {
alert("Form has been reset");
}
Try it yourself »
Other Extensions
Event Object