Just a quick tip on how to select all text when focus is given to a textarea or input (only if the value has not changed) .
$("input, textarea").focus(
function()
{
// only select if the text has not changed
if(this.value == this.defaultValue)
{
this.select();
}
}
)



7 comments:
Thx for this tip.
My problem solved, hehe :D
Thanks. I didn't even know the defaultValue property existed.
Thanks, your post helped me to solve this problem in about 20 seconds.
Quick and simple, thanks. Maybe it would be better if you directly select the spec. input field using the jQuery css selectors for attr. like this: $('input[name=name-of-inputfield]').focus(...));
Nice, thx!
Thanks!
thanks! doesn't appear to work in chrome. it will select the text then it gets deselected immediately after.
Post a Comment