HTML onreset Event Attribute

Description

The event attribute onreset allows you to set the script to fire when the form is reset. For example, when you click the Reset button of an <input> element with type "reset" ( type = "reset" ) or using JavaScript:

function resetFunction () {
   document.getElementById("idForm").reset();
}

Syntax

<element onreset="script">

Values

  • scriptThe name of the script to use when the event has been triggered.

Example

<!DOCTYPE html> 
  <html> 
    <head>
      <title>onreset event</title> 
    </head> 
    <body> 
    <form onreset="testFunction()">
    Enter something and discard:<br>
    <input type="text" name="info"><br>
    <input type="reset"> 
    </form> 
<script> 
function testFunction() { 
  alert ("The form has been reset!"); 
} 
</script> 
  </body> 
</html>

Supported Tags

<form>

Browser Support

Desktop
Explorer Edge Chrome Firefox Opera Safari
XYesYesYesYesYes
Tablets / Mobile
Android Chrome Firefox Opera Safari Samsung
YesYesYesYesYesYes