javascript reset form – How to reset (clear) form through JavaScript?

javascript reset form to The reset button is an input element with type=”reset”: first button simply resets all the fields using this.form.reset() as described earlier. also You can programmatically reset a form using JavaScript, too.

javascript reset form

we can use the reset button to reset the form. Reset or clear a form using JavaScript, with the reset() method. You can simply use the JavaScript reset() method to reset a web form.

$("#member.frm")[0].reset();
//faster version:
$("#member")[0].reset();

javascript reset form
javascript reset form

Or without jQuery:
document.getElementById("member").reset();

JavaScript reset Example

index.html

<!DOCTYPE html>   
<html>  
<head>   
<title> reset() method - www.pakainfo.com</title>  
</head>  
<body style = "text-align: center;">  
<div style = "background: pink;">  
  <font color = "red" size = "6px">  
    <b>Simple Example of the reset() method </b>  
  </font>  
 </div>  
    <div style = "background: lightblue;">  
    <form id = "loginFrm" action = "#" style = "font-size: 20px;" >  
    <p> First Name: <input type = "text" id = "fname" /></p>  
    <p> Last Name: <input type = "text" id = "lname" /></p>  
    <p> E-mail Id:   <input type = "email" id = "email" /></p>  
    <p> Age:         <input type = "number" id = "age" /></p>  
    <input type = "submit">  
    <input type = "button" value = "Reset data" onClick = "fun()"/>  
    </form>  
    </div>  
<script>  
 function fun(){  
   document.getElementById("loginFrm").reset();  
 }   
</script>  
  
</body>  
</html>  

How to reset or clear a form using JavaScript?

index.html

<!DOCTYPE html>
<html>
   <head>
      <title>Reset HTML form - www.pakainfo.com</title>
   </head>
   <body>
      <form id="memberFrm">
         Member Name<br><input type="text" name="sname"><br>
         Member Subject<br><input type="password" name="ssubject"><br>
         <input type="button" onclick="newFunction()" value="Reset">
      </form>
      <script>
         function newFunction() {
            document.getElementById("memberFrm").reset();
         }
      </script>
   </body>
</html>

Don’t Miss : How To Reset The Text Field In A Form Using JavaScript?

Free Live Chat for Any Issue

I hope you get an idea about javascript reset form.
I would like to have feedback on my infinityknow.com.
Your valuable feedback, question, or comments about this Article are always welcome.
If you enjoyed and liked this post, donโ€™t forget to share.

Rate this post