Page 1 of 1

highlight keywords in textarea

Posted: Fri Feb 02, 2007 2:01 am
by potato
Hi,

i'm looking for a way to highlight some words in a textarea without affecting the content of it.
in the textarea is some html-code, so that doesn't may change when there are words highlighted.

for example, the content of the area looks like this:

<table><tr><td>some keywords to test</td></tr></table>

i already have a higlight script, but it changes the content.
when i want to search for the word 'keywords' in the example above, i would have a result like this:


<table><tr><td>some <font style='color:blue; background-color:yellow;'>keywords</font> to test</td></tr></table>

so my content changes, what i actualy wants is that it leaves the content, but just highlights the keywords, so that in the submitted form, there isn't any highlight in it.


I hope you understand what i'm trying to explain
:?

greetings

Posted: Fri Feb 02, 2007 2:52 am
by Kieran Huggins
You can't add style to individual words in a standard textarea.

That being said, you could use a rich-text textarea replacement like FCKeditor...or you could have a live preview DIV.

Re: highlight keywords in textarea

Posted: Fri Feb 02, 2007 11:37 am
by jyhm
Would style sheets help?

Code: Select all

<style>
#highlighter   {
                       font-color: #000;
                       font: 11px verdana, sans-serif;
                       }

#highlighter:hover   {
                       font-color: blue;
                       font: 11px verdana, sans-serif;
                       }

#highlighter:active   {
                       font-color: #fff;
                       font: 11px verdana, sans-serif;
                       }
</style>

Code: Select all

<div class="highlighter"><table><tr><td>some keywords to test</td></tr></table></div>