onreset Event

Example

Call a function 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.


Description

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 Yourself »

In JavaScript:

object.onreset = function(){myScript};
Try it Yourself »

In JavaScript, using the addEventListener() method:

object.addEventListener("reset", myScript);
Try it Yourself »


Technical Details

Bubbles: Yes
Cancelable: Yes
Event type: Event
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 »

Copyright 1999-2023 by Refsnes Data. All Rights Reserved.