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">
</form>
<script>
  // get the form by its id
  var form = document.getElementById("myForm");
  // reset the form
  form.reset();
</script>

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.

document.getElementById("resetBtn").click();

Also Read:

Categorized in: