Languages
[Edit]
EN

JavaScript - reset form example

0 points
Created by:
Wayne
415

In this article, we would like to show you how to reset form in JavaScript.

Quick solution:

// get form element by id and reset
document.querySelector("#form-id").reset();

 

Practical example

In this example, we will reset myForm using reset() function.

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<body>
  <form id="my-form">
    Username: <input type="text"><br>
    Password: <input type="password"><br>
    <input type="button" value="Reset" onclick="resetForm()">
  </form>
  <script>

    var myForm = document.querySelector('#my-form');

    function resetForm() {
        myForm.reset();
    }

  </script>
</body>
</html>
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join