We can reset a form to default input values by using Reset button. But on several occasion we need to reset the form by using JavaScript ( or DHTML ) where based on some condition we can reset the form. To do this we will be assigning one ID to the form. By using that ID we can reset the form. Here is the simple syntax to reset a form by JavaScript.
document.getElementById("f1").reset();
Here f1 is the form ID.
Uses of Reset in comment posting.
In this page and in other pages also we are using a form asking visitors to post their comments. If the form validation is not cleared then you will get a message asking you to take corrective measures to validate the form. If the validation is passed then the data is stored in the database and the form needs to be reset. This is achieved by using DHTML where if validation is passed then the form is reset through JavaScript.