I know that we can bind a handler to a form onsubmit... But how to add a handler to a reset event form? (usually by clicking on <input type="reset">)
onsubmit
<input type="reset">
Or ... Maybe there is no such event ... So, the question is, how to handle this?
(right now I want to start the handler after the reset event, but one day I may need to execute before the reset event)
According to MDN , the tag <form>supports the event onreset.
<form>
onreset
onreset ; . , reset onchange , reset, .
onchange
- reset, onblur reset ( reset - ). , , setTimeout, script reset. , .
onblur
< reset "
<form action="form_action.php" onreset="return confirm('Do you really want to reset the form?');"> .... </form>
, , , .
Instead, <input type='reset'>you can use an element <button>with a click handler that first calls the method form.reset(), then you can add all the scripts that you will need after the reset action.
<input type='reset'>
<button>
form.reset()
You tried
<form onreset="action()">
It seems I am working to run a script before resetting the form. As for after ... I don't think this is supported, maybe setTimeout will do the trick.