onreset event
Example
Execute JavaScript after the form is reset:
Try it »
Definition and Usage
The onreset event is triggered after the form has been reset.
Browser support
| Events | |||||
|---|---|---|---|---|---|
| onreset | Yes | Yes | Yes | Yes | Yes |
Syntax
In HTML:
<
element
onreset="
myScript
">Try it
In JavaScript:
object
.onreset=function(){
myScript
};
Try it
In JavaScript, use the addEventListener() method:
object
.addEventListener("reset",
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: | Yes |
| Event type: | Event |
| Supported HTML tags: |
More examples
Example
Display the content written into the text field before the form is reset:
var x = document.getElementById("myInput");
alert("Before reset, text content is: " + x.value);
Try it »
Example
Use the reset() method of the HTML DOM Form Object to reset the form. After execution, the onreset event is triggered and a prompt message is displayed.
// Reset all element values of the form with id="myForm"
function myResetFunction() {
document.getElementById("myForm").reset();
}
// Show a prompt after the form is reset
function myAlertFunction() {
alert("Form has been reset");
}
Try it »
Event Object