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 JavaScript, using the addEventListener() method:
object.addEventListener("reset", 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> |
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 »