I know we can attach a handler to the form onsubmit
... But how can we add a handler to the form reset event? (usually when clicking on <input type="reset">
)
Or... Maybe there is no such event... So the question becomes on how to work-around that?
(right now, I want to run a handler after the reset event; but someday I might need to run before the reset event)
According to MDN, the <form>
tag supports an onreset
event.
Onreset
fires before the actual resetting of the form; there doesn't appear to be any event for after resetting. I tested to see if the reset would fire an onchange
event for the inputs whose values are reset, but it does not appear to.
A workaround for doing something after resetting might be to set a flag on reset, and then use the onblur
event of the reset button (so after you reset, it would run the next time you click on something else). An alternate workaround, of course, is to trigger a setTimeout so that your script would run a short time after the reset. Either one is a bit of a hack, I'm afraid.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With