Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set background color 1

Status
Not open for further replies.

DotNetGnat

Programmer
Mar 10, 2005
5,548
IN
Guys,

If i have something like this:

e1=document.CreateElement("textarea")
e1.setAttribute("id","txtarea1")
e1.setAttribute("rows","5")
e1.setAttribute("cols","15")
e1.setAttribute("style","background-color: red")

or
e1.setStyle("background-color","red")

why does not the bold code work similar to the other attributes...how can i set the background color to my textarea field...

-DNG


 
Code:
e1.style.backgroundColor = "red";


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
What browser are you using? Both of these work in IE:
Code:
document.getElementById('ta').style.backgroundColor = 'red';
document.getElementById('ta').style.background = 'red';


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Make sure you use backgroundColor and not background-color


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
what do i do if need to set the font face and font color of the text in the text area...

thanks

-DNG
 
Code:
e1.style.color = 'blue';
e1.style.fontFamily = 'Verdana, Arial, Helvetica, sans-serif';
e1.style.fontSize = '12pt';
e1.style.fontWeight = 'bold';
The style attribute in JavaScript is the same as it would be in CSS, except that where in CSS you have a hyphen, remove it and Caplitalize the next letter.

I don't know why the single quotes should make a difference though. JavaScript doesn't care which you use.


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Tracy,
i have one quick question...one of my elements is a button and i want to invoke a function on the button click...how can i do that...

i tried something like:

e1=document.CreateElement("input")
e1.setAttribute("type","button")
e1.setAttribute("id","but1")
e1.setAttribute("onClick","return button1();")

it did not work...

-DNG

 
Here's my favorite reference for DHTML and CSS methods, properties, attributes, events, etc. The Microsoft Developer's Network:
Here's what I got from objects/button/events/onclick:
Code:
e1.onclick = [i]aFunction[/i];
Note that you can ONLY specify the NAME of a function, you cannot pass any parameters to the function. It's an inconvenience to be sure, but using an event object (different in IE and FF) you can get the thing that was clicked. Or you could just write a different function for each button you have to code an event handler with no parameters for, and have that function pass the appropriate parameter(s) to another, common, function.


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top