The Wayback Machine - https://web.archive.org/web/20240620143513/https://www.geeksforgeeks.org/how-to-reset-a-form-using-jquery-with-reset-method/
Open In App

How to reset a form using jQuery with .reset() method?

Last Updated : 14 Dec, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will implement the reset functionality with the reset() method in jQuery and reset all the input fields of a form. Resetting anything will set everything back to its original state. JQuery doesn’t have a reset() method, but native JavaScript does. So, we convert the jQuery element to a JavaScript object.

Syntax:

$('element_selector')[0].reset();
OR
$('element_selector').get(0).reset();

Example 1: The below example implements the reset functionality using the reset() method and $(‘element_selector’)[0].reset(); syntax:

HTML




<!DOCTYPE html>
<html>
 
<head>
    <title>Try jQuery Online</title>
    <script src=
    </script>
    <script>
        $(document).ready(function() {
            $("#resetBtn").click(function(e) {
                //$("#d").trigger("reset");
                //$("#d").get(0).reset();
                e.preventDefault();
                $("#d")[0].reset()
            });
        });
    </script>
</head>
 
<body>
    <center>
        <h1 style="color:green">GeeksforGeeks</h1>
        <h4>
        Click on "Submit" to submit and
        remaining resets to get form to original state.
        </h4>
        <form id="d" name="geek">
            <table cellspacing="0" cellpadding="3" border="1">
                <tr>
                    <td align="center">Username</td>
                    <td>
                        <input type="text" name="name" />
                    </td>
                </tr>
                <tr>
                    <td align="center">Email</td>
                    <td>
                        <input type="text" name="name" />
                    </td>
                </tr>
                <tr>
                    <td align="center">Password</td>
                    <td>
                        <input type="password" />
                    </td>
                </tr>
            </table>
            <input type="submit" value="Submit" />
        </form>
        <button id="resetBtn">Reset Form</button>
    </center>
</body>
 
</html>


Output:

formResetter

Example 2: This example implements the reset functionality using the reset() method and $(‘element_selector’)[0].reset(); syntax:

HTML




<!DOCTYPE html>
<html>
 
<head>
    <title>Try jQuery Online</title>
    <script src=
    </script>
    <script>
        $(document).ready(function() {
            $("#resetBtn").click(function(e) {
                //$("#d").trigger("reset");
                //$("#d").get(0).reset();
                e.preventDefault();
                $("#d").get(0).reset()
            });
        });
    </script>
</head>
 
<body>
    <center>
        <h1 style="color:green">GeeksforGeeks</h1>
        <h4>
        Click on "Submit" to submit and
        remaining resets to get form to original state.
        </h4>
        <form id="d" name="geek">
            <table cellspacing="0" cellpadding="3" border="1">
                <tr>
                    <td align="center">Username</td>
                    <td>
                        <input type="text" name="name" />
                    </td>
                </tr>
                <tr>
                    <td align="center">Email</td>
                    <td>
                        <input type="text" name="name" />
                    </td>
                </tr>
                <tr>
                    <td align="center">Password</td>
                    <td>
                        <input type="password" />
                    </td>
                </tr>
            </table>
            <input type="submit" value="Submit" />
        </form>
        <button id="resetBtn">Reset Form</button>
    </center>
</body>
 
</html>


Output:

formResetter

jQuery is an open source JavaScript library that simplifies the interactions between an HTML/CSS document, It is widely famous with it’s philosophy of “Write less, do more”. You can learn jQuery from the ground up by following this jQuery Tutorial and jQuery Examples.



Similar Reads

HTML | DOM Form reset() Method
The Form reset() method in HTML DOM is used to reset all the value of form elements and use the default value. This method works as a reset button. It does not contain any parameters. Syntax: formObject.reset() Example: C/C++ Code &amp;lt;!DOCTYPE html&amp;gt; &amp;lt;html&amp;gt; &amp;lt;head&amp;gt; &amp;lt;title&amp;gt; HTML DOM Form reset() Met
1 min read
How to clear form after submit in Javascript without using reset?
Forms in javascript are used to take the selective or required information from the user. There are various areas and purposes to use forms, i.e, in recruitment, when applying for some kind of jobs, or for asking some types of queries. It is easy to distribute form when it is not online but when it comes to the online field one cannot distribute a
2 min read
How to create a Reset Button in form using HTML ?
In this article, we will learn how to create a Reset Button in HTML forms.  The reset button is used to reset all the form data values and set them to their initial default value. In case of user enters the wrong data then the user can easily correct it by clicking on the "Reset Button". Syntax:&lt;input type="reset"&gt;Approach: First, we have to
1 min read
How to reset all form values using a button in HTML ?
To reset all field values in an HTML form, you can use the &lt;input type="reset"&gt; attribute. When the reset button is clicked, the form will be restored to its default state, without any of the values that were previously entered in the fields, checkboxes, or radio buttons. This can be useful in various scenarios. In this article, we will focus
1 min read
How to reset selected value to default using jQuery ?
The task is to reset the value of the select element to its default value with the help of jQuery. There are two approaches that are discussed below:Approach 1: First select the options using jQuery selectors then use prop() method to get access to its properties. If the property is selected then return the default value by using defaultSelected pr
2 min read
How to reset input type = "file" using JavaScript/jQuery?
In this article, we will learn how to rest input type="file" using Javascript/Jquery. We can easily reset a file using jQuery and HTML. This can also be done using JavaScript and HTML. These are the following ways: Table of Content Using the wrap method in jQueryUsing file.value = ''Using wrap method in jqueryApproach 1: Using the wrap method in jQ
2 min read
HTML | DOM Input Reset form Property
The Input Reset form Property in HTML DOM is used for return the reference of the form containing the input reset button field. It is read-only property. Syntax: resetObject.form Return Values: It returns a string value which specify the reference of the form containing the Input reset field Below example illustrates the Input reset form property.
1 min read
How to submit a form or a part of a form without a page refresh using jQuery ?
In this article, we will learn how to submit a form or a part of a form without a page refresh using JQuery, &amp; will understand its implementation through the example. How to prevent an HTML form to submit? Generally, when we submit a form then we should click a submit button then our page will navigate to another route as it is mentioned in the
3 min read
jQuery :reset Selector
The jQuery :reset Selector is used to select the input element having a reset field button.i.e &lt;input type="button"&gt;. Syntax: $(":reset")Example 1: In this example, we will select the input element which has a reset field button by using jQuery :reset Selector. C/C++ Code &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;script src= &quot;h
1 min read
p5.Image reset() Method
The reset() method of p5.Image in p5.js is used to restart an animated GIF and play it from its beginning state. It can be used with a button press or user input to restart the GIF animation. It does not accept any parameters. Syntax: reset() Parameters: This method does not accept any parameter. The example below illustrates the reset() method in
1 min read