Change color of textbox in javscript
How to change color of textbox(some part of string only, not entire text in textbox) in javascript?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Hemant KumarRank #1,202 · 1.5K reputationPosted Oct 18, 2011, 3:33 AM EDT
If you really need it your way, then do the following:
Replace
#textboxidwith the desired selector, and color with the desired color.Note the following does the same for one property:
Now in Javascript
document.getElementById("fName").classname = document.getElementById("fName").classname + " error"; // this adds the error class document.getElementById("fName").classname = document.getElementById("fName").classname.replace(" error", ""); // this removes the error classTulasiRank #2,544 · 549 reputationPosted Oct 18, 2011, 3:39 AM EDT
i have a textbox with content 'aaa@bbb@ccc'
what i need is , i want to change color of symbol( ' @') in textbox using Javascript
Hemant KumarRank #1,202 · 1.5K reputationPosted Oct 18, 2011, 3:57 AM EDT
You can use CSS and some JavaScript to accomplish that. First, set the waiting text color and background color using CSS. Then, from the onload tag, have some JavaScript change the colors again:
It may be easier to move the JavaScript to a separate function, so you're not cluttering up the tag too much, but I'll leave that up to you.
The code in the onload event changes the color (of the text) and the background color properties of the style object. This style object belongs, in this example, to the text box.