Sometimes, we want to select all text in HTML text input when clicked with JavaScript.
In this article, we’ll look at how to select all text in HTML text input when clicked with JavaScript.
How to select all text in HTML text input when clicked with JavaScript?
To select all text in HTML text input when clicked with JavaScript, we call the input’s select
method on click.
For instance, we write
<label for="userid">User ID</label>
<input onClick="this.select();" value="Please enter the user ID" id="userid" />
to call this.select
when we click on the input to select all the text in it when we click on the input.
Conclusion
To select all text in HTML text input when clicked with JavaScript, we call the input’s select
method on click.