views:

1773

answers:

3

What is a JavaScript or jQuery solution that will select all of the contents of a textbox when the textbox receives focus?

+6  A: 
$(document).ready(function() {
    $("input[type=text]").focus(function() { $(this).select(); } );
});
John Sheehan
Also just for extra info:"input[type=text]" now can be "input:text"regards
Ricardo Vega
+3  A: 
<input type="text" onfocus="this.select()" />
Zach
It's much nice to keep markup separated from script.
Jonathan Sampson
+3  A: 
$(document).ready(function() {
  $("input[type=text]").focus().select();
});
Tomas Kirda
+1 because this was what I needed, but it's not the answer to THIS question.
Cros
Thanks, yes it was my mistake.
Tomas Kirda