GlobalEventHandlers.onreset
The onreset property of the
GlobalEventHandlers mixin is an event handler that
processes reset events.
The reset event fires when the user clicks a reset button in a form
(<input type="reset">).
Syntax
target.onreset = functionRef;
Value
functionRef is a function name or a function
expression. The function receives an Event object as its sole
argument.
Example
This example logs the current Event.timeStamp whenever you reset the
form.
HTML
<form id="form">
<label>Test field: <input type="text"></label>
<br><br>
<button type="reset">Reset form</button>
</form>
<p id="log"></p>
JavaScript
function logReset(event) {
log.textContent = `Form reset! Time stamp: ${event.timeStamp}`;
}
const form = document.getElementById('form');
const log = document.getElementById('log');
form.onreset = logReset;
Result
Specifications
| Specification |
|---|
| HTML Standard # handler-onreset |
Browser compatibility
BCD tables only load in the browser