Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to auto select an input field and the text in it on page load

Upon page load I want to move the cursor to a particular field. No problem. But I also need to select and highlight the default value that is placed in that text field.

like image 884
derick Avatar asked Oct 17 '08 00:10

derick


People also ask

How do you select all text in input?

The HTMLInputElement. select() method selects all the text in a <textarea> element or in an <input> element that includes a text field.

How do you select input text in react?

To select the all text in an input field, we can use the e. target. select() method in react. Here is an example of a functional react component, that selects the text by clicking on the input field.


1 Answers

From http://www.codeave.com/javascript/code.asp?u_log=7004:

var input = document.getElementById('myTextInput');  input.focus();  input.select();
<input id="myTextInput" value="Hello world!" />
like image 167
John Millikin Avatar answered Sep 25 '22 15:09

John Millikin