How to reset the table

A common requirement on a web page containing a form is to reset it to its original state.

I think that some time ago, many forms had a "reset" button, although now I see it being used less and less.

The reset button is ainputElement andtype="reset":

<input type="reset">

You can also reset the form programmatically using JavaScript.

All you need is the form element reference:

const form = document.querySelector('form')

Then you can callreset()The method will do:


This will clear all the elements in the form and restore them to their original state.

Download mine for freeJavaScript beginner's manual

More browser tutorials: