Jens Jens - 2 years ago 613
Javascript Question

Change color of specific words in textarea

I'm building a Sql query builder and would like to change the text color of a word in a textarea when the user types in words like SELECT, FROM, WHERE.

I've searched around a bit and beyond this ( I unfortunately do not come any further.

Example code


<textarea name="query_field_one" id="query_field_one" onkeyup="checkName(this)"></textarea>


function checkName(el)
if (el.value == "SELECT" ||
el.value == "FROM" ||
el.value == "WHERE" ||
el.value == "LIKE" ||
el.value == "BETWEEN" ||
el.value == "NOT LIKE" ||
el.value == "FALSE" ||
el.value == "NULL" ||
el.value == "TRUE" ||
el.value == "NOT IN")

else {'#FFF'



But this example deletes the color when I type further.

What I want is this:

Right way

I've tried something with Keyup in combination with Contains in jQuery but that did not result in much.



I hope someone can help me with an example or sites where I can find more information .

Regards, Jens

Answer Source
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download