- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
We have seen the basics of the reset() function, now let’s move to its syntax −
var element = document.getElementById( Id_of_required_form ). element.reset()
In the above syntax, “Id_of_required_form” is the id of the form which we want to reset or clear. We have used the ‘getElementById’ method of the DOM to get the form and stored that in a variable name ‘element’.
After that, by using the method reset() we reset or clear the form with the id ‘Id_of_required_form’ element by calling it.
We have seen the syntax to reset or clear a form by getting its id and reset() method, let’s see the complete algorithm step by step to understand it in a better way −
Creating a user form
In these steps, we will create the form in which we will define or create many input boxes for user input to fill the form and a button which will call the function to delete the object from the dropdown list.
In the form, we have created some input boxes by using the <input> tag where the user can write the data.
These input spaces will be of type text and number to get the user input in the required type.
In the form after defining ‘inputs’ to take user input, we will define an input field using the <input> tag and will make it of type button and we will define the ‘onclick’ event which will call the function which we will define later in the script.
Defining script or function to remove
In these steps, we will define the function which will be called in the ‘onclick’ event of the above-defined button.
Initially, we will create a function using the ‘function’ keyword and will give it a name that will be called in the ‘onclick’ event.
In the defined function we will create a variable to store the return value from the call to the ‘document.getElementById()’ method.
We will pass the ‘id’ of the above-defined form as the parameter to the call to the ‘document.getElementById()’ method.
By using the reset method with the variable (which contains the return value of the call to the method) we can reset every input field to empty.
In this example, we are going to implement the above-defined algorithm step by step, let’s implement the code −
In the above output, we got one form in which there are some input spaces, where the user can provide some input and at last, there is a reset button which will reset the form to the original or initial form.
- How to reset or clear an edit box in Selenium?
- HTML DOM Form reset() method
- How to clear HTML form fields with jQuery?
- HTML DOM Input Reset form property
- How to reset or change the MySQL root password?
- How to clear screen using C#?
- How to clear screen using python?
- How to clear screen using Java?
- How to validate a form using jQuery?