Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • jQuery Tutorial
  • jQuery Selectors
  • jQuery Events
  • jQuery Effects
  • jQuery Traversing
  • jQuery HTML & CSS
  • jQuery AJAX
  • jQuery Properties
  • jQuery Examples
  • jQuery Interview Questions
  • jQuery Plugins
  • jQuery Cheat Sheet
  • jQuery UI
  • jQuery Mobile
  • jQWidgets
  • Easy UI
  • Web Technology
Open In App
Next Article:
How to submit a form or a part of a form without a page refresh using jQuery?
Next article icon

How to Reset Form using jQuery with reset() Method?

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

Reset a form means clear all input fields data and returns to their initial default values. It can be useful where a user wants to clear all entered data or you want to reset the form after a successful submission. The reset() method can easily reset the form data after clicking the reset button or successful form submission.

Resetting a Form using JavaScript reset() Method

The reset() method is a built-in JavaScript method that can be used to reset a form. When invoked, this method restores the form’s fields to their default values. The reset() method is used with jQuery to reset the form fields.

Syntax

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

Example 1: In this example, we use reset() method to reset the form data. The form will be reset when user click on “Reset Form” button.

HTML
<!DOCTYPE html> <html>  <head>     <title>         Reset a form using jQuery         with reset() method     </title>      <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">     </script> </head>  <body>     <h1 style="color:green">         GeeksforGeeks     </h1>      <h4>         Reset Form using Reset Form         or Form Submit Buttons     </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>         <br>          <input type="submit" value="Submit" />          <button id="resetBtn">             Reset Form         </button>     </form>      <script>         $(document).ready(function () {             $("#resetBtn").click(function (e) {                 //$("#d").trigger("reset");                  //$("#d").get(0).reset();                  e.preventDefault();                 $("#d")[0].reset()             });         });      </script> </body>  </html> 

Output

Form-Reset

Example 2: In this example we use jQuery to reset a form with ID d when the “Reset Form” button is clicked. It prevents the default behavior and ensures the form returns to its initial state.

HTML
<!DOCTYPE html> <html>  <head>     <title>         Reset a form using jQuery         with reset() method     </title>      <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">     </script> </head>  <body style="margin: 0 0 0 50px;">     <h1>GeeksforGeeks</h1>      <h4>         Reset Form using Reset Form         or Form Submit Buttons     </h4>      <form id="d" name="geek">         <table cellspacing="0" cellpadding="3" border="1">             <tr>                 <td>Username</td>                 <td>                     <input type="text" name="name" />                 </td>             </tr>             <tr>                 <td>Email</td>                 <td>                     <input type="email" name="email" />                 </td>             </tr>             <tr>                 <td>Password</td>                 <td>                     <input type="password" />                 </td>             </tr>         </table>         <br>          <input type="submit" value="Submit" />          <button id="resetBtn">             Reset Form         </button>     </form>      <script>         $(document).ready(function () {             $("#resetBtn").click(function(e) {                  //$("#d").trigger("reset");                  //$("#d").get(0).reset();                  e.preventDefault();                 $("#d").get(0).reset()              });          });      </script> </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.



Next Article
How to submit a form or a part of a form without a page refresh using jQuery?

T

Tejashwi5
Improve
Article Tags :
  • JQuery
  • Web Technologies
  • jQuery-Questions

Similar Reads

  • How to Refresh a Page using jQuery?
    Refreshing a page using jQuery allows you to programmatically reload the current webpage, ensuring updated content or resetting the page's state. It can be done using location.reload() method. Table of Content Using location.reload() MethodUsing history.go(0)Using location.replace() with Current Pag
    3 min read
  • How to reset selected value to default using jQuery?
    Resetting a selected value to its default in a dropdown or select element is a common requirement in web development to enhance user experience. jQuery, a popular JavaScript library, simplifies this task by providing easy-to-use methods for manipulating DOM elements. By using jQuery, you can quickly
    3 min read
  • How to stop a form submit action using jQuery ?
    In this article, we will learn how to stop a form submit action using jQuery. By default, the HTML form submits automatically. Submitting automatically leads to reloading the whole page again and again. Therefore for performing any operation, we have to prevent its default submission. Given a form,
    3 min read
  • How to submit a form or a part of a form without a page refresh using jQuery?
    How to prevent an HTML form to submit?When submitting a form, clicking the submit button usually navigates to a new route as specified in the form's action attribute. However, this can be done in the background using event.preventDefault(), which blocks the default event behavior. By attaching an on
    2 min read
  • jQuery UI Accordion refresh() Method
    jQuery UI consists of GUI widgets, visual effects, and themes implemented using HTML, CSS, and jQuery. The jQuery UI is great for building UI interfaces for the webpages. The jQuery UI Accordion refresh() method is used to refresh the widget. It is used to process any headers and panels that are add
    2 min read
  • How to make Refresh icon using jQuery Mobile ?
    jQuery Mobile is a web-based technology used to make responsive content that can be accessed on all smartphones, tablets, and desktops. In this article, we will be making Refresh icon using jQuery Mobile. Approach: First, add jQuery Mobile scripts needed for your project. <link rel="stylesheet" h
    1 min read
  • How to clear form after submit in Javascript without using reset?
    Forms in JavaScript serve to gather specific user information, essential in various contexts like recruitment or inquiry submissions. While offline forms can be freely distributed, online forms must maintain a consistent structure for all users. After filling out a form, submission is crucial, but d
    2 min read
  • jQuery UI Tabs refresh() Method
    jQuery UI consists of GUI widgets, visual effects, and themes implemented using HTML, CSS, and jQuery. jQuery UI is great for building UI interfaces for the webpages. The jQuery UI Tabs widget is used to create a single content area with multiple panels that are associated with a header in a list. T
    3 min read
  • How to create a Form Popup using jQuery Mobile ?
    jQuery Mobile is a web based technology used to make responsive content that can be accessed on all smartphones, tablets and desktops. In this article, we will be creating a form popup using jQuery Mobile. Approach: Add jQuery Mobile scripts needed for your project. <link rel=”stylesheet” href=”h
    2 min read
  • jQuery UI Button refresh() Method
    jQuery UI consists of GUI widgets, visual effects, and themes implemented using HTML, CSS, and jQuery. jQuery UI is great for building UI interfaces for the webpages. The jQuery UI Button refresh() method is used to refresh the button element. This method does not accept any parameter. Syntax: $(".s
    1 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences