Javascript: Highlight All Text In Textfield On Focus

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

During my development for the company’s information system, 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=”javascript:this.select()”>

Popularity: 33% [?]

Comments:

6 Responses to “Javascript: Highlight All Text In Textfield On Focus”


  1. [...] Javascript: Highlight All Text In Textfield On Focus Juli 14, 2006 — Arief Fajar Nursyamsu This post has been moved. Click here. [...]


  2. Jadi pingin coba, sekali sekali dibahas tentang VALIDATION dong mas.. via JS


  3. Insya Alloh saya bahas mas, nanti versi yang bahasa Inggris nitip di tempat sampeyan ya mas :D


  4. Hi,

    Thanks for this simple little tip, will prove useful.

    regards
    George


  5. Hey, I came across this blog post while searching for help with JavaScript. I have recently changed browsers from Safari to Mozilla Firefox 3.1. Now I seem to have a issue with loading JavaScript. Every time I browse page that needs Javascript, the site freezes and I get a “runtime error javascript.JSException: Unknown name”. I can’t seem to find out how to fix it. Any aid is very appreciated! Thanks


  6. Hi Joe,
    Have you try to reinstall Firefox? Or you may try this link: http://www.java.com/en/download/help/javascript.xml

Leave a Reply

RSS