How to automatically select an input field and text in it when loading a page

When loading a page, I want to move the cursor to a specific field. No problems. But I also need to select and highlight the default value that is placed in this text box.

+47
javascript html
Oct 17 '08 at 0:43
source share
7 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!" /> 
+78
Oct 17 '08 at 0:44
source share

In your input tag, put the following:

 onFocus="this.select()" 
+24
Nov 13 '10 at 23:00
source share

Do this when loading the page:

 window.onload = function () { var input = document.getElementById('myTextInput'); input.focus(); input.select(); } 
 <input id="myTextInput" value="Hello world!" /> 
+13
Oct 17 '08 at 6:03
source share

try it. this will work on both Firefox and Chrome.

<input type="text" value="test" autofocus="autofocus" onfocus="this.select()">

+12
Jun 06 '16 at 8:35
source share

I found a very simple method that works well:

 <input type="text" onclick="this.focus();this.select()"> 
+5
Dec 05 '14 at 23:14
source share

when using jquery ...

HTML:

 <input type='text' value='hello world' id='hello-world-input'> 

JQuery

 $(function() { $('#hello-world-input').focus().select(); }); 

example: https://jsfiddle.net/seanmcmills/xmh4e0d4/

0
Jul 01 '16 at 2:00
source share
 <input type="text" value="test" onclick="this.select()"> 

check here

http://www.n-alforat.com/vb/ext/test/code.htm

-one
Mar 15 '16 at 7:32
source share



All Articles