dynamically changing background color HELP please

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Billy

    dynamically changing background color HELP please

    Hello,
    I'm having a problem dynamically changing the color of a table background.

    I'm not sure exactly how to word this, but I'll give an example.

    I have a function called greentored(prop name)

    i want to be able to change the following to a different color:
    document.all.pr opname.style.vi sibility

    but substitute the propname with the variable that I'm sending over.

    Here is what I had written before but it did not work, it should be easy to
    understand what i'm trying to do:

    function greentored(prop name) {

    changecolor = "document.a ll." + propname + ".style.backgro und";

    changecolor = "green";

    }

    I understand why this doesn't work because all i'm doing is reasigning
    "changecolo r" to equal green, rather then setting the property of the first
    instance of "changecolo r" to green. I hope I explained this well enough.

    Thanks,

    Billy


  • kaeli

    #2
    Re: dynamically changing background color HELP please

    In article <101fvo51tbgi28 4@corp.supernew s.com>, billy@jimtown.o rg
    enlightened us with...[color=blue]
    > Hello,
    > I'm having a problem dynamically changing the color of a table background.
    >[/color]

    And it only works in IE, too.
    [color=blue]
    > I'm not sure exactly how to word this, but I'll give an example.
    >
    > I have a function called greentored(prop name)
    >
    > i want to be able to change the following to a different color:
    > document.all.pr opname.style.vi sibility
    >[/color]

    That is IE only syntax.
    Not all of us use IE.

    Visibility has no color. It is a property all by itself
    (style.visibili ty). Most block elements have a style.backgroun dColor
    property. Some block elements, notably those with text like P and DIV,
    have a style.color property.

    I will assume that what you are sending is the name of an element.
    For this to be cross-browser, what you need is an id.
    I will show you a function that is for DOM browsers only (IE5+/NN6
    +/Mozilla/Opera6+ etc). You're on your own for NN4 - I wiped my hands on
    that one.

    For this example, I have an element that has a background color
    property.
    <div id="myId">my div contents</div>
    The function would then be called as
    greenToRed("myI d");

    The function is defined in the head of the document as
    (Watch for word-wrap)

    function greenToRed(prop name)
    {
    var changeColor="gr een";
    if (document.getEl ementById(propn ame) && document.getEle mentById
    (propname).styl e)
    {
    document.getEle mentById
    (propname).styl e.backgroundCol or=changeColor;
    }
    }

    HTH

    --
    --
    ~kaeli~
    Found God? If nobody claims Him in 30 days, He's yours to
    keep.



    Comment

    • Billy

      #3
      Re: dynamically changing background color HELP please

      Thanks.... I've just started working on an addition to my website and you
      reminded me i
      need to test on Netscape as well as IE. yes, i did give my example wrong...
      i
      did mean "style.backgrou nd" but your help was helpful none the less.
      Thanks.

      Billy

      "kaeli" <tiny_one@NOSPA M.comcast.net> wrote in message >[color=blue]
      > And it only works in IE, too.
      >[color=green]
      > > I'm not sure exactly how to word this, but I'll give an example.
      > >
      > > I have a function called greentored(prop name)
      > >
      > > i want to be able to change the following to a different color:
      > > document.all.pr opname.style.vi sibility
      > >[/color]
      >
      > That is IE only syntax.
      > Not all of us use IE.
      >
      > Visibility has no color. It is a property all by itself
      > (style.visibili ty). Most block elements have a style.backgroun dColor
      > property. Some block elements, notably those with text like P and DIV,
      > have a style.color property.
      >
      > I will assume that what you are sending is the name of an element.
      > For this to be cross-browser, what you need is an id.
      > I will show you a function that is for DOM browsers only (IE5+/NN6
      > +/Mozilla/Opera6+ etc). You're on your own for NN4 - I wiped my hands on
      > that one.
      >
      > For this example, I have an element that has a background color
      > property.
      > <div id="myId">my div contents</div>
      > The function would then be called as
      > greenToRed("myI d");
      >
      > The function is defined in the head of the document as
      > (Watch for word-wrap)
      >
      > function greenToRed(prop name)
      > {
      > var changeColor="gr een";
      > if (document.getEl ementById(propn ame) && document.getEle mentById
      > (propname).styl e)
      > {
      > document.getEle mentById
      > (propname).styl e.backgroundCol or=changeColor;
      > }
      > }
      >
      > HTH
      >
      > --
      > --
      > ~kaeli~
      > Found God? If nobody claims Him in 30 days, He's yours to
      > keep.
      > http://www.ipwebdesign.net/wildAtHeart
      > http://www.ipwebdesign.net/kaelisSpace
      >[/color]



      Comment

      • kaeli

        #4
        Re: dynamically changing background color HELP please

        In article <101ikie3r98350 a@corp.supernew s.com>, billy@jimtown.o rg
        enlightened us with...[color=blue]
        > Thanks.... I've just started working on an addition to my website and you
        > reminded me i
        > need to test on Netscape as well as IE.[/color]

        Don't forget Opera. :)

        And ask around for people to test with Safari and other browsers they
        may have, especially IE for Mac.

        --
        --
        ~kaeli~
        Never mess up an apology with an excuse.



        Comment

        Working...