How to run javascript code when form reset?

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">)

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)

+5
source share
4 answers

According to MDN , the tag <form>supports the event onreset.

onreset ; . , reset onchange , reset, .

- reset, onblur reset ( reset - ). , , setTimeout, script reset. , .

+6

< reset "

<form action="form_action.php" onreset="return confirm('Do you really want to reset the form?');">

....

</form>
+2

, , , .

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.

+2
source

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.

+1
source

All Articles