👀 Live Preview
Fill the form and click Reset — status updates via reset:
Waiting for reset…

The onreset attribute is an inline event handler for the reset event on a <form> element. It runs when the form is reset to its initial values — typically when the user clicks a <input type="reset"> or <button type="reset"> button, or when your code calls form.reset(). Use it to show confirmation feedback, clear custom preview UI, or reset related widgets that are not form controls. Call event.preventDefault() to cancel the reset. Prefer addEventListener("reset", …) in production.
Inline JS.
Form cleared.
Target element.
Trigger button.
Clear previews.
Preferred way.
onreset AttributeThe primary purpose of onreset is to run custom logic when a form returns to its default state — for example showing a “Form cleared” message, wiping a live preview div, or resetting validation styling that the browser does not clear automatically.
Native reset only restores form controls to their initial value, checked, or selected state. Anything outside the form — or custom JavaScript state — may need your handler to clean up.
Inside addEventListener("reset", fn), call event.preventDefault() if you need to block the reset — for example after asking the user to confirm.
Set onreset on <form>, or assign form.onreset in JavaScript:
<form onreset="handleReset()">
<input type="text" name="name">
<input type="reset" value="Reset">
</form>
<script>
form.onreset = handleReset;
form.addEventListener("reset", handleReset);
</script>reset event fires on the form.<form> elements only.type="reset" buttons or form.reset().event.preventDefault() in listeners to cancel the reset.form.addEventListener("reset", handler).The onreset attribute accepts a string of JavaScript code:
onreset="handleReset()" — Call a named function.onreset="status.textContent = 'Cleared'" — Inline statement.form.onreset = () => { … } — property assignment.function handleReset(event) {
status.textContent = "Form has been reset!";
preview.textContent = "";
// event.preventDefault(); // uncomment to cancel reset
}
form.addEventListener("reset", handleReset);| Property / event | When it fires | Notes |
|---|---|---|
reset | Form reset requested | onreset |
submit | Form submitted | onsubmit |
type="reset" | Reset button click | Inside the form |
form.reset() | Programmatic reset | Also fires event |
event.preventDefault() | Inside reset handler | Cancel the reset |
| Element | Supported? | Notes |
|---|---|---|
<form> | Yes | Primary target |
<input type="reset"> | Trigger | Not the handler target |
<button type="reset"> | Trigger | Same as input reset |
<input>, <div> | No | Use form-level handler |
form.reset() | Related | JS API — fires reset event |
onreset vs onsubmit vs form.reset()| API | When it fires | Typical use |
|---|---|---|
onreset | Form cleared to defaults | Feedback, clear custom UI |
onsubmit | Form submitted | Validate, send data |
form.reset() | When you call it | Clear after success |
input type="reset" | User clicks Reset | Built-in clear button |
Inline form handler, dynamic assignment, and clearing a custom preview with addEventListener.
Fill the form and click Reset — status updates via reset:
Waiting for reset…
Show feedback when the user clicks Reset:
<form onreset="resetForm()">
<label for="name">Name:</label>
<input type="text" id="name" name="name">
<input type="reset" value="Reset">
</form>
<script>
function resetForm() {
document.getElementById("status").textContent = "Form has been reset!";
}
</script>Clicking the Reset button fires reset on the form. The inline attribute runs resetForm() so you can react after (or before) fields revert.
Assign the handler on the form at runtime:
<script>
document.getElementById("dynamicForm").onreset = function () {
log.textContent = "This form is being reset!";
};
</script>Assigning form.onreset is equivalent to the inline form attribute. Attach after the form exists in the DOM.
Native reset clears inputs but not extra UI — handle that in your listener:
form.addEventListener("reset", function () {
setTimeout(function () {
preview.textContent = "Preview: (empty)";
}, 0);
});The reset event fires before fields update. A short setTimeout lets you sync custom UI after the browser finishes resetting controls.
aria-label.aria-live="polite" on status text when the form is cleared.Or form.reset().
onreset runs.
Default values.
Form + custom UI.
The reset event and onreset handler are supported in all modern browsers, including Internet Explorer 9+.
onreset supportAll major browsers fire reset on forms when reset is triggered.
Bottom line: Reliable for form reset handling in all modern browsers.
onreset on the <form>addEventListener("reset", …) in productionalert() for every resetonreset on individual inputsThe onreset attribute runs JavaScript when a form returns to its default values — useful for feedback and cleaning up custom UI that native reset does not touch.
Attach it to the form, pair with type="reset" buttons, use event.preventDefault() when you need to block a reset, and prefer addEventListener in production.
onresetBookmark these before wiring form reset logic.
<form>.
ScopeTrigger.
ButtonCancel.
APIClear extra.
PatternClear only.
Gotchareset event fires on a form — when the user clicks Reset or form.reset() is called.event.preventDefault() in a reset event listener to cancel the reset.onreset clears the form to defaults. onsubmit runs when the user submits data — opposite actions.form.addEventListener("reset", handler) is preferred — you need it for preventDefault() and multiple listeners.Practice the onreset attribute with inline handlers and custom preview clearing in the Try It editor.
5 people found this page helpful