...

View Full Version : Setting Background color of a button?



ggallen
03-17-2004, 09:19 PM
In HTML it's setup like:

<BUTTON NAME="BTN-GENERAL" OnClick="showgeneral();" STYLE="background:yellow">General</BUTTON>

I want to change the background color in my
function. I've tried using:

document.getElementById("BTN-GENERAL").style.backgroundColor="grey";

but get an error....

I've tried using style.backgroundcolor="grey", but it doesn't
work.

What is the sub-property name to set the background color?

Thanks
George

ggallen
03-17-2004, 09:38 PM
so, the problem isn't the coding, it's "grey"
Apparantly, grey isn't a known color.

I'll have to figure out the # code for grey.

George

Antoniohawk
03-17-2004, 09:40 PM
Try


document.getElementById('BTN-GENERAL').style.backgroundColor='gray';


Your problem was that "grey" needed to be spelled "gray". Works fine in Mozilla, but of course IE doesn't like it when you don't follow their rules. Dictionary.com says that it can be spelled either way, and here's wikipedia's view:

http://en.wikipedia.org/wiki/Gray

ggallen
03-17-2004, 09:44 PM
OOOOOO. It's gray instead of grey.

Well, it also worked with silver! Hard to screw that spelling up

George

warhammerdude20
03-17-2004, 10:56 PM
its alot easier(in my point of view) to just go like:



function changeColor(){
window.document.*whatever.*whatever.style.BgColor="yellow";
}


in my opinion

shlagish
03-18-2004, 02:20 AM
ggallen, the # value of a color is simple to figure out :)
it's basically specifying how much of red, green and blue the color should containt (for a maximum of 255)
But the values are given in hexadecimal.
the two first numbers are for red, the two middle numbers are for green and the two last numbers are for blue.
ex: #F34D55
means
red: F3
green: 4D
blue: 55
or in decimal:
red: 243
green: 77
blue: 85

If you don't want to bother with hexadecimal, you could also use the rgb technique.

rgb(243,77,85)

Does that help at all?

Oh and for gray, as long as there is the same amount of red, green and blue, it will give gray.
ex:
#DDDDDD, #444444, #5F5F5F are all grays.
same as rgb(221,221,221), rgb(68,68,68) and rgb(95,95,95) respectivly.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum