JavaScript Coder

javascript clear form

Using JavaScript to reset or clear a form

Using an HTML ‘Reset’ button is an easy way to reset all form fields to their default values. For instance, the code snippet below shows an <input> field of type “reset”, which on being clicked resets all the form fields: <input type="reset" value="Reset Form"> In fact, we could also use the form's reset() method to achieve the same effect, using a simple button element: <input type="button" value="Reset Form" onClick="this.form.reset()" /> These methods are very convenient to use, but they do not provide the functionality of clearing all the fields, including their default values.

Continue Reading →