Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you clear a plain HTML form after onsubmit?

After the onsubmit event has fired and the form has been submitted (via an action="mailto:[email protected]") , is there a way to then clear the form, close the window or what? Is there a post submit that I can hook into via JavaScript. This must be a client side only solution.

like image 913
Mike T Avatar asked Jun 15 '09 19:06

Mike T


People also ask

How do you clear form data after submit in HTML?

Form reset() Method The reset() method resets the values of all elements in a form (same as clicking the Reset button). Tip: Use the submit() method to submit the form.

How do I clear text in a form after submitting?

To clear an input field after submitting:Add a click event listener to a button. When the button is clicked, set the input field's value to an empty string. Setting the field's value to an empty string resets the input.

How do you reset HTML?

The <input type="reset"> defines a reset button which resets all form values to its initial values.


1 Answers

A quick and easy solution:

<form action="mailto:[email protected]"
    onsubmit="this.submit(); this.reset(); return false;">
like image 125
jimyi Avatar answered Sep 26 '22 00:09

jimyi