Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jul 2003
    Location
    NJ - #29 if you must know
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Setting Background color of a button?

    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

  • #2
    Regular Coder
    Join Date
    Jul 2003
    Location
    NJ - #29 if you must know
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #3
    Senior Coder
    Join Date
    Aug 2002
    Location
    Kansas City, Kansas
    Posts
    1,518
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Try
    Code:
    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
    Last edited by Antoniohawk; 03-17-2004 at 09:45 PM.

  • #4
    Regular Coder
    Join Date
    Jul 2003
    Location
    NJ - #29 if you must know
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts
    OOOOOO. It's gray instead of grey.

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

    George

  • #5
    Regular Coder
    Join Date
    Dec 2003
    Posts
    132
    Thanks
    0
    Thanked 0 Times in 0 Posts
    its alot easier(in my point of view) to just go like:

    Code:
    function changeColor(){
     window.document.*whatever.*whatever.style.BgColor="yellow";
    }
    in my opinion

  • #6
    Senior Coder
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    1,063
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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.
    Shawn


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •