change background-color of textarea


I am trying to change the background-color of a "textarea" element in an html page.
This is the code:

void CHtmProps::changeBgColor(int color)
 MSHTML::IHTMLDocument2Ptr spDoc=GetHtmlDocument();
 MSHTML::IHTMLElementPtr spBodyElement=spDoc->Getbody();
 MSHTML::IHTMLElementCollectionPtr pElc= spBodyElement->Getall();
 MSHTML::IHTMLElementPtr spElement=0;
 _bstr_t id, bg;
  int len = pElc->length;
  for(int i = 0; i < len; i++)
  _variant_t va((long) i, VT_I4);
  spElement = pElc->item(va);
  _bstr_t bstrTagName = spElement->GettagName();
  if (!stricmp(STRING bstrTagName,"textarea")) // "IsuHtmlEditor"))
  _variant_t color((long) color, VT_I4);
  BSTR bstrAttName =SysAllocString(L"background-color");              

it does not work.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mark StegglesWeb DeveloperCommented:

You can easily control the background-color of a textarea with css...

textarea {background-color:#369;}

VapiSoftAuthor Commented:
Hi Steggs,

I know I can do that in the textarea tag, but I beed to do it dynamically.
Either from a java-script function, or from a CHtmView method.
The code that I wrote is inside CHtmProps which is derived from ChtmlView
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
function changecolor(hex){
<a href="#" onclick="changecolor('#fff666')">yellow</a>
<a href="#" onclick="changecolor('#000fff')">blue</a>
<textarea id="color_change" style="width:300px;height:200px"></textarea>
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

VapiSoftAuthor Commented:
Hi cx323:

Your code works as stand alone, but it does not work in my HTML because I have "editor.js" attach to it.
When I remove the "editor.js" it works. Do you know how I can solve this problem (I am not familer with java-script programming).
More info:
I am using "htmlArea" to edit HTML.
I am trying to change the button "background-color" to change the entire background (rather than the text-background).
could you post a link to your site online so i can look at the issue their since i've never used htmlArea.  and by background do you mean the body background color or what?
VapiSoftAuthor Commented:

I am not uning it in my site ( but in my application.
I downloaded it from

It is amaizing peace of software, but it caused me a lot of problems.
One problem is this, and the other (which I am breaking my head on) is that under ChtmlView id does not process the Enter key.

i just had a quick glance through the source and it looks like this will work:

look for this part of the editor.js file:
// fgColor and bgColor
  else if (cmdID == 'ForeColor' || cmdID == 'BackColor') {
    var oldcolor = _dec_to_rgb(editdoc.queryCommandValue(cmdID));

paste in this code:
// fgColor and bgColor
  else if (cmdID == 'ForeColor' || cmdID == 'BackColor') {
    var oldcolor = _dec_to_rgb(editdoc.queryCommandValue(cmdID));
    var newcolor = showModalDialog(_editor_url + "popups/select_color.html", oldcolor, "resizable: no; help: no; status: no; scroll: no;");
      if(cmdID == 'BackColor' && newcolor != null){ = newcolor;return;}
    if (newcolor != null) { editdoc.execCommand(cmdID, false, "#"+newcolor); }

only this line is new:
if(cmdID == 'BackColor' && newcolor != null){ = newcolor;return;}

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
VapiSoftAuthor Commented:
Hi cx323,

I want to thank you very much.
Because i don't know JS I tried to do it for my application and spent a lot of time (tto much time) to it.
VapiSoftAuthor Commented:
One more thing if I may.
How do i initialize it that it will be open in a certain color (not white).
I set the HTML page from my application like that
<textarea name="IsuHtmlEditor"  style="width:800; height:150;background-color: #6699ff">
but when I open it with the editor.js it is white.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.