onreset Event
Definition and Usage
An onreset event occurs when the form is reset.
Instance
Example 1
Execute JavaScript when the form is reset:
<form onreset="myFunction()"> Enter name: <input type="text"> <input type="reset"> </form>
Example 2
Display the text in the text field inserted before reset:
var x = document.getElementById("myInput"); alert("Before reset, the text was: " + x.value);
Example 3
The reset() method of the HTML DOM Form object is used to reset the form. When this happens, the onreset event is triggered, which triggers an alert function.
// Reset the values of all elements in the form with id="myForm" function myResetFunction() { document.getElementById("myForm").reset(); } // Display some text when the form is reset function myAlertFunction() { alert("The form was reset"); }
Syntax
In HTML:
<element onreset="myScript">
In JavaScript:
object.onreset = function(){myScript};
In JavaScript, use the addEventListener() method:
object.addEventListener("reset", myScript);
Note:Internet Explorer 8 or earlier versions do not support addEventListener() Method.
Technical Details
Bubbling: | Support |
---|---|
Cancelable: | Support |
Event Type: | Event |
Supported HTML Tags: | <form> |
DOM Version: | Level 2 Events |
Browser Support
Events | Chrome | IE | Firefox | Safari | Opera |
---|---|---|---|---|---|
onreset | Support | Support | Support | Support | Support |