
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
HTML DOM Form reset() method
The HTML DOM Form reset() method is used for resetting all the values of the form elements and displaying the default values that are specified using the value attribute of the form elements. It acts as a reset button to clear form data and it doesn’t take any kind of parameters.
Syntax
Following is the syntax for form reset() method −
formObject.reset()
Example
Let us look at an example of the Form reset() method −
<!DOCTYPE html> <html> <head> <style> form{ border:2px solid blue; margin:2px; padding:4px; } </style> <script> function ResetForm() { document.getElementById("FORM1").reset(); document.getElementById("Sample").innerHTML="Form has been reset"; } </script> </head> <body> <h1>Form reset() method example</h1> <form id="FORM1" method="post" action="/sample_page.php"> <label>User Name <input type="text" name="usrN"></label> <br><br> <label>Age <input type="text" name="Age"></label> <br><br> <input type="submit" value="SUBMIT"> <input type="button" onclick="ResetForm()" value="RESET"> </form> <p id="Sample"></p> </body> </html>
Output
This will produce the following output −
On clicking the RESET button −
In the above example −
We have first created a form with id=”FORM1”, method=”post” and action=”/sample_page.php”. It contains two input fields with type text, a submit button and a reset button.
<form id="FORM1" method="post" action="/sample_page.php"> <label>User Name <input type="text" name="usrN"></label> <br><br> <label>Age <input type="text" name="Age"></label> <br><br> <input type="submit" value="SUBMIT"> <input type="button" onclick="ResetForm()" value="RESET"> </form>
The RESET button on being clicked executes the ResetForm() function.
<input type="button" onclick="ResetForm()" value="RESET">
The ResetForm() method gets the <form> element using the document object getElementById() method and calls the reset() method on it. This clears all the data in the form elements. Finally using the innerHTML property we display the intended text reflecting this change inside a paragraph with id “Sample” −
function ResetForm() { document.getElementById("FORM1").reset(); document.getElementById("Sample").innerHTML="Form has been reset"; }
- Related Articles
- HTML DOM Input Reset form property
- HTML DOM Form method Property
- HTML DOM Form submit() method
- HTML DOM Input Reset object
- HTML DOM Input Reset name property
- HTML DOM Input Reset type property
- HTML DOM Input Reset value property
- HTML DOM Input Reset autofocus property
- HTML DOM Input Reset disabled property
- HTML DOM Form object
- HTML DOM Object form Property
- HTML DOM Legend form Property
- HTML DOM Textarea form Property
- HTML DOM Form name Property
- HTML DOM Fieldset form property
