I\'m after the following functionality:
If you can use jQuery then you can do something like;
$("#myInputField").focus(function(){
// Select input field contents
this.select();
});
// Add this behavior to all text fields
$("input[type=text]").focus(function(){
// Select field contents
this.select();
});
Taken from HERE
You should remember to do a return false; event.stopPropagation(); event.preventDefault()
like so:
$('input[type="text"]').live('click', function (event) {
this.select();
event.stopPropagation();
event.preventDefault();
return false;
});
http://jsfiddle.net/7rYLV/
Just delay it by a millisecond with setTimeout
:
$('input[type="text"]').live('focus', function() {
var inp = this;
setTimeout(function() {
inp.select();
}, 1);
});
http://jsfiddle.net/HmQxZ/14/
What's happening is some other browser event is setting the selection after you've selected the text. So, by waiting a millisecond, you let all the browser events finish, and then select the text. Nothing will undo it now.
You may want to add
event.preventDefault();
return false;
to your function (the first one). That may fix the other browsers.
Also, add event
to the function sig:
$('input[type="text"]').live('focus', function (event) {