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.
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!" />
In your input tag, put the following:
onFocus="this.select()"
Do this when loading the page:
window.onload = function () { var input = document.getElementById('myTextInput'); input.focus(); input.select(); }
try it. this will work on both Firefox and Chrome.
<input type="text" value="test" autofocus="autofocus" onfocus="this.select()">
I found a very simple method that works well:
<input type="text" onclick="this.focus();this.select()">
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/
<input type="text" value="test" onclick="this.select()">
check here
http://www.n-alforat.com/vb/ext/test/code.htm