0

I have a <input type="text" value="Hi! Enter Here" >

How to open this in selected mode and cursor on the input field.

We just start writting into it

S L
  • 14,262
  • 17
  • 77
  • 116
user426795
  • 11,073
  • 11
  • 35
  • 35
  • You mean something like http://api.jquery.com/focus/ ? – Davor Lucic Apr 07 '11 at 11:54
  • Is this question incomplete? Regardless, this might help: http://stackoverflow.com/questions/985272/jquery-selecting-text-in-an-element-akin-to-highlighting-with-your-mouse – jbrookover Apr 07 '11 at 11:55
  • Please be sure your users would appreciate this auto-focus behaviour, I recall *loathing* Google's search page as my home-page simply because I'd start typing with the caret in the address bar and find at least half the characters of the URL in the search box... – David Thomas Apr 07 '11 at 11:58

3 Answers3

2

use jquery focus() function

$('input').focus();

Or better

<input type="text" value="Hi! Enter Here" id="someid">

and

$('#someid').focus();

check working example here.

For select and focus

$('#someid').focus().select();

or

$('#someid').focus(function (){$(this).select();});

On jsfiddle.net

S L
  • 14,262
  • 17
  • 77
  • 116
1
$("input").focus(); 

Read more at http://api.jquery.com/focus/

Peeter
  • 9,282
  • 5
  • 36
  • 53
1

Set the id of the input

<input type="text" id="myText" value="Hi! Enter Here" >

Then add this jQuery

$(function() {
  $("#myText").focus();
});
curtisk
  • 19,950
  • 4
  • 55
  • 71