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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Highlighting the Contents of a textbox control

Status
Not open for further replies.

NatGreen

Programmer
Apr 19, 2002
90
US
Does anyone know how to Highlight the entire contents of a textbox control?

Thanks in advance,
NatGreen
 
Hey Nat,

I'm guessing you mean that you want to have the textboxes change background color, or be bolded, or something as the user tabs through/selects the different controls?

Here's one way you can do it:
Check out this thread: thread855-396964
Here's how I'd change the code there to work in your case:
Only take a control object in, no need for a boolean. THe control object it needs to be passed is the page first (so in the calling code, you just put ThisFunction(Me)).

Now, in the part where I actually have the objTextControl having its properties set, what you're going to want to code is:
objTextControl.Attributes.Add("onFocus", "do this")
objTextControl.Attributes.Add("onBlur"), "do this")

Not 100% if those are the javascript commands, but you get the picture: each textbox will get an attribute added for when it gets focus (change the backcolor, bold, etc.) and when it loses focus (reset defaults).

This way, when the client is tabbing through the text controls, the javascript will already be written and the client code will do all the changes for you.

hth

D'Arcy
 
What I am trying to do is this:

document.formname.textbox.focus()
document.formname.textbox.select()

However, when I run this javascript code on a asp:Textbox control. I get a javascript error saying object does not support this. I would like to select the contents of the text box so that the user can begin typing and over write the previous value.

Any ideas?

Thanks.
 
Ah, ok.

Well for the focus part, check out this thread:
thread855-400181

For the select part...interesting problem. Off the top of my head, I don't know of a way. if I come accross something, I'll let you know.

D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top