onreset Event
Example
Execute a JavaScript when a form is reset:
<form onreset="myFunction()">
Enter name: <input type="text">
<input type="reset">
</form>
Try it yourself »
More "Try it Yourself" examples below.
Definition and Usage
The onreset event occurs when a form is reset.
Browser Support
Event | |||||
---|---|---|---|---|---|
onreset | Yes | Yes | Yes | Yes | Yes |
Syntax
In HTML:
<element onreset="myScript">Try it
In JavaScript:
object.onreset=function(){myScript};Try it
In JavaScript, using the addEventListener() method:
object.addEventListener("reset", 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 |
More Examples
Example
Display the text that was inserted in a text field before it was reset:
var x = document.getElementById("myInput");
alert("Before reset, the text
was: " + x.value);
Try it yourself »
Example
Using the reset() method of the HTML DOM Form Object to reset the form. When this happens, the onreset event fires, which will trigger an alert function.
// Reset the value of all elements in a form with id="myForm"
function
myResetFunction() {
document.getElementById("myForm").reset();
}
// Alert some text
when the form is reset
function myAlertFunction() {
alert("The form was reset");
}
Try it yourself »
Event Object