April 17, 2024, 2:03 a.m. | Joseph Ochego

DEV Community dev.to

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();





Links


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


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

document dom event fields file form forms however html instances javascript them

Data Architect

@ University of Texas at Austin | Austin, TX

Data ETL Engineer

@ University of Texas at Austin | Austin, TX

Lead GNSS Data Scientist

@ Lurra Systems | Melbourne

Senior Machine Learning Engineer (MLOps)

@ Promaton | Remote, Europe

Business Data Scientist, gTech Ads

@ Google | Mexico City, CDMX, Mexico

Lead, Data Analytics Operations

@ Zocdoc | Pune, Maharashtra, India