onreset
The onreset event in HTML is triggered when a form is reset, allowing developers to run code in response to the reset action.
onreset
The onreset
event attribute in HTML is activated when a form is reset, either by using a reset <button>
or through JavaScript. This enables developers to trigger specific actions or scripts when the form's <input>
values are cleared.
Syntax
In HTML
index.html
<element onreset="myScript">
In JS
script.js
object.onreset = function(){myScript};
addEventListener()
function is used. In JavaScript, the
script.js
object.addEventListener("reset", myScript);
Example
::event-onreset
::
index.html
<!DOCTYPE html>
<html>
<body>
<p>When you reset the form, a function is triggered which alerts some text.</p>
<form onreset="myFunction()">
Enter name: <input type="text">
<input type="reset">
</form>
<script>
function myFunction() {
alert("The form was reset");
}
</script>
</body>
</html>
Values
Conclusion
The onreset
event provides a useful way to handle actions when a form is reset, whether by the user or through a <script>
. By utilizing this event, developers can create more dynamic and responsive forms, offering better user interactions and customized feedback when the form is cleared.