How to reset an HTML form on submit using JavaScript
Joseph Ochego

Joseph Ochego @thejoernal

About: A self-taught web developer. Very enthusiastic about tech, and Linux. And a Mechanical Engineer by profession.

Location:
Bangalore, India
Joined:
Mar 8, 2024

How to reset an HTML form on submit using JavaScript

Publish Date: Apr 17 '24
7 0

By default, HTML forms are reset and all fields are cleared when we submit them.

However, in instances where you use the preventDefault() method in the JavaScript file, the form doesn't reset automatically.

In such situations, we have to trigger the reset event manually using the following JavaScript method:

document.getElementById("formId").reset();
Enter fullscreen mode Exit fullscreen mode

Links

https://www.w3schools.com/jsref/met_form_reset.asp

This is a cross-post from the original in my blog site

Comments 0 total

    Add comment