You can reset a form using the reset()method in JavaScript. Here is an example of how to use it:

<form id="myForm">
  <input type="text" name="firstName">
  <input type="text" name="lastName">
  <input type="submit" value="Submit">
  <input type="reset" value="Reset">
  // get the form by its id
  var form = document.getElementById("myForm");
  // reset the form

You can also use document.getElementById("myForm").reset() directly. It’s also possible to reset the form by selecting the reset button and triggering a click event on it.


Also Read:

Categorized in: