There's a little bit of an oddity happening here. focus
happens on mousedown, but cursor placement happens on click
(i.e. a mousedown
followed by a mouseup
). When the cursor is placed, any selection goes away.
So, you'll most likely want to keep your focus
event (for tabbing and trigger
ing purposes) but also add a click
or a mouseup
handler to do the actual select in the case of a click.
$('input[type="text"]').focus(function() {
$(this).select();
}).click(function() {
if ($(this).val() === 'Your default value')
{
$(this).select();
}
});
The if
exists so that once a user has customized text in your input, they can click around without selecting text. Although, that doesn't really apply to a readonly
text input, so it may be safely removed.
Edit:
Code seems to be inconsistent at best, so this may not be the solution.