Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Highlight text within textbox? 1

Status
Not open for further replies.

FancyPrairie

Programmer
Oct 16, 2001
2,917
US
I want to set focus to a text box and automatically highlight the text within the text box. Setting focus is no problem, but how do I highlight the text?
 
You don't, you can change the background colour of a text box and the color of the text, you can highlight the text in a font, div or span tag though.
 
Try using the "select" method after the "focus" method:

Code:
el.focus();
el.select();

I'm not sure how cross-browser it is, but give it a whirl anyway.

Hope this helps,
Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Apologies - I hadn't realised I was posting in the HTML forum.

FancyPrairie,

if you need to dissuss my JavaScript solution further, you should take it to the JavaScript forum (forum216).

Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top