1. Home
  2. Computing & Technology
  3. JavaScript

Highlighting Text

Join the Discussion

Questions? Comments?

Highlighting the content of a form field when the field is selected makes it easier for your visitor to completely replace the field content with their own simply by starting typing their new input. They can just as easily modify the existing highlighted content simply by pressing an arrow key before typing anything else.

Here is an example input field that shows how the highlighting works:

Creating this effect is so simple that we can easily include the entire code within the field definition in the HTML. It looks like this:

<input type="text" value="default value"
onfocus="this.select();" />
Explore JavaScript
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. JavaScript

©2009 About.com, a part of The New York Times Company.

All rights reserved.