• do you mean as the user is typing them into the text area? or after they have been typed in and sent somewhere? I'm sorry I don't really understand the question. Tony Crockford about 10 years ago
  • i have written some text in textarea control then i tried to search some word from it, if that word is there then it should highlighted or it should have a different color as textarea doesn't parse HTML tags so it is very difficult to do it anyways it can be done using iframes but i am just wondering that , is it possible with textarea jagdish about 10 years ago

1 answer

danwellman 5600

If the value of the textarea is already set (e.g. it is set programmatically by a script or hand coded into the page) you could try wrapping the words to be coloured in spans with class names in order to apply color CSS.

If a visitor is typing into the textarea, you would need to do something with Javascript, and probably the keyup event so that whenever a character is typed into the textarea the script checks wether the character is the final charcater in some words you have defined (probably as part of an array) and if so, wraps the whole word in a span with the appropriate class name.

If you can give us more information about your intent and the structure of the page, a more detailed answer should be possible :)

Update You can't put code into a textarea ><

If you're coloring text that must be typed by visitors, i.e. a <textarea> must be used, consider using a <div> element that the text they type into the textarea is copied into, and the <span> elements can be used in the <div>, a similar setup to how comments are typed/previewed here

Answered about 10 years ago by danwellman