#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    Belgium
    Posts
    60
    Rep Power
    12

    javascript blinking cell question


    I want to let some cell's of a table blink. I don't get any error code's. Got no clue whta could be wrong with my code.

    <script>
    function foobar()
    {
    set();
    unSet();
    }
    function unSet()
    {
    document.getElementById(1).bgColor="454545";
    }
    function set()
    {
    document.getElementById(1).bgColor="E0DDDD";
    }
    </script>
    <body bgcolor="676767" onLoad="setTimeout('foobar()',1000)">
  2. #2
  3. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Oct 2001
    Location
    New Zealand
    Posts
    1,774
    Rep Power
    24
    Walking through the function:

    You call foobar() after 1 second.. and this calls set, then unset immediately after, so after 1 second your bgColor turns to 454545 then immediately to E0DDDD, so you wont see it happen. But:
    document.getElementById(1).bgColor="454545";

    should read something like:
    document.getElementById("1").backgroundColor="#454545";

    to work correctly. If you want it to blink then you should have something more like:


    <script>
    function unSet()
    {
    document.getElementById("1").backgroundColor="#454545";
    setTimeout("set()",1000);
    }
    function set()
    {
    document.getElementById("1").backgroundColor="#E0DDDD";
    setTimeout("unset()",1000);
    }
    </script>
    <body bgcolor="676767" onLoad="setTimeout('set()',1000)">

    You could however put it all in one function and use a test:

    <script>
    function set()
    {
    if (document.getElementById("1").backgroundColor == "#454545") {
    document.getElementById("1").backgroundColor="#E0DDDD";
    } else {
    document.getElementById("1").backgroundColor="#454545";
    }
    setTimeout("set()",1000);
    }
    </script>
    <body bgcolor="676767" onLoad="setTimeout('set()',1000)">

IMN logo majestic logo threadwatch logo seochat tools logo