Open In App

HTML DOM Form reset() Method

Last Updated : 08 Oct, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The reset() method in the HTML DOM is used to reset a form fields to their default values. When a form is reset, all user input is cleared, and the fields revert to their initial states.

Syntax

formObject.reset()

Example: In this example, clicking the reset button clears the form inputs.

html
<!DOCTYPE html>
<html>

<head>
    <title>
        HTML DOM Form reset() Method
    </title>
</head>

<body>
    <h1>GeeksforGeeks</h1>

    <h2>DOM Form reset() Method</h2>

    <!-- HTML code to create form -->
    <form action="#" method="post" id="users">
        <label for="username">Username:</label>
        <input type="text" name="username" id="Username">
        <br><br>

        <label for="password">Password:</label>
        <input type="password" name="password" id="password">
        <br><br>

        <input type="reset" id="GFG" value="Reset">
    </form>

    <!-- script to use reset() method -->
    <script>
        document.getElementById("GFG").reset();
    </script>
</body>

</html>

Output

DOM-Form-Reset

Supported Browsers: The browser supported by DOM Form reset() method are listed below:

  • Chrome 1
  • Edge 12
  • Firefox 1
  • Opera 8
  • Safari 3

Next Article
Practice Tags :

Similar Reads