Changing the color of part of a string (textbox/textarea)

They have: 2 posts

Joined: Jan 2005

Hey there! I am trying to do some validation on text for a project that I am working on here at work. I have n textboxes (or textareas depending on how the user has the form set up). The form itself is used to send a message to either a pager or an email address. Depending on what type of pager the user has, we are only allowed to send a certain number of characters to the user. For example, if they have a numeric only pager, we can only send 24 characters. What I am trying to do is show the user which characters will be truncated by highlighting them in red. We have a max_chars variable that is getting pulled from the database.

Right now I am able to count the total number of characters in all the textboxes and spit out an error. Does anyone here know how to change the font color inside of the textbox in the middle of a string? Again, this is inside of a textbox so I need to pass the sting back to my html page.

Thanks in advance!

He has: 1,758 posts

Joined: Jul 2002

Errrm... styling the text in a text area is easy as long as you have a uniform style. Unfortunatly from my experiments it doesn't seem to be possible to put html within the text area field and that means that you can't differentiate between the bad and good bits of code by wrapping a span or something like that.

I think the solution would require use of DHTML but I don't know all that much about that so I can't really help you much futher. The forum does have a few javascript wiz kids though, so maybe they can help.

Andy

They have: 2 posts

Joined: Jan 2005

I've been able to change all of the text to a different color (and that is pretty easy) but it's the portion of the string that I'm having troubles with. Thanks for the reply!

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.