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>

Try it yourself

Example 2

Display the text in the text field inserted before the reset:

var x = document.getElementById("myInput");
alert("Before reset, the text was: " + x.value);

Try it yourself

Example 3

Use the reset() method of the HTML DOM Form object 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();
}
// Prompt some text when the form is reset
function myAlertFunction() {
  alert("The form was reset");
}

Try it yourself

Syntax

In HTML:

<element onreset="myScript">

Try it yourself

In JavaScript:

object.onreset = function(){myScript};

Try it yourself

In JavaScript, use the addEventListener() method:

object.addEventListener("reset", myScript);

Try it yourself

Note:Internet Explorer 8 or earlier versions do not support Méthode addEventListener().

Détails techniques

Bubbling : Support
Annulable : Support
Type d'événement : Event
Balises HTML prises en charge : <form>
Version DOM : Événements de niveau 2

Support du navigateur

Événement Chrome IE Firefox Safari Opera
onreset Support Support Support Support Support