Javascript: Highlight All Text In Textfield On Focus

Posted in Web Development on April 3st, 2008 | (4,799) Comments

During my development for the company’s information system, look I found that automatically highlight all text in a textfield can help users to easily delete it’s content, rather than have to block the text or use “Ctrl+A”.

I use Javascript event onFocus() and select() function. Here is how to add it on the textfield properties:

<input name=”country” type=”text” id=”country” value=”Highlighted Text” onFocus=””>