Languages
[Edit]
EN

JavaScript - reset form example

0 points
Created by:
Wayne
265

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>
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