WEB TUTORIALS
PRACTICE EXAMPLES
HTML REFERENCES
CSS REFERENCES
PHP REFERENCES

How to Reset a Form Using jQuery or JavaScript

Topic: JavaScript / jQueryPrev|Next

Answer: Use the reset() Method

You can simply use the JavaScript reset() method to reset a form as shown in the example below:

  • <!DOCTYPE html>
  • <html lang="en">
  • <head>
  • <title>Reset Form Using JavaScript</title>
  • <script>
  • function resetForm() {
  •     document.getElementById("myForm").reset();
  • }
  • </script>
  • </head>
  • <body>
  •     <form action="/examples/html/action.php" method="post" id="myForm">
  •         <label>First Name:</label>
  •         <input type="text" name="first-name">
  •         <input type="submit" value="Submit">
  •     </form>
  •     <br>
  •     <button type="button" onclick="resetForm();">Custom Reset Button</button>
  • </body>
  • </html> 

In jQuery there is no method like reset(), however you can use the jQuery trigger() method to trigger the JavaScript native reset() method, like this:

  • <!DOCTYPE html>
  • <html lang="en">
  • <head>
  • <title>Reset Form Using jQuery</title>
  • <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
  • <script>
  • $(document).ready(function(){
  •     $(".reset-btn").click(function(){
  •         $("#myForm").trigger("reset");
  •     });
  • });
  • </script>
  • </head>
  • <body>
  •     <form action="/examples/html/action.php" method="post" id="myForm">
  •         <label>First Name:</label>
  •         <input type="text" name="first-name">
  •         <input type="submit" value="Submit">
  •     </form>
  •     <br>
  •     <button type="button" class="reset-btn">Custom Reset Button</button>
  • </body>
  • </html> 

Related FAQ

Here are some more FAQ related to this topic:

Your Feedback:

We would love to hear from you, please drop us a line.