To clear the entire input field without having to delete the whole thing manually Or what if there is already a pre-suggested input present in the input field, that the user doesn’t want. There could be many scenarios. Therefore, in this article, we are going to learn about how to clear the input field.
There are two ways to do this and both are super easy and short. Let us check out both of them.
Method 1: Clearing Input on Focus.
- Create an input field.
- Set the onfocus attribute to NULL using this.value
Method 2: Clearing Input with the help of button.
<button onclick="document.getElementById('InputID').value = ''>
- Create a button.
- Get the id of input field.
- Set the value NULL of input field using document.getElementById(‘myInput’).value = ”
- JQuery | Set the value of an input text field
- How to validate input field while focusout ?
- How to disable browser Autocomplete on web form field/input tag?
- How to detect value change on hidden input field in JQuery ?
- JQuery | Set focus on a form input text field on page load
- HTML | input Tag
- HTML | DOM Input URL value Property
- HTML | <input type="url">
- HTML | DOM Input URL name Property
- HTML | <input> src Attribute
- HTML | <input> alt Attribute
- HTML | <input type="tel">
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : shubham_singh