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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How would I make a cell in a table randomly turn red every 300 ms ? 1

Status
Not open for further replies.

heather143

Programmer
Feb 13, 2008
1
US


Hi, I am very new to Javascript and am having a problem writing this program, so I was wondering if one of you experts could help me. This is the problem I am having. Its probably simple to you guys.

I am trying to do this :
when the "Start" button is clicked a random cell changes its background color to red for 350ms, then back to white, then another cell becomes red, then to a different cell, every 350ms.
It is supposed to be in a 3 x 3 table.
I am trying to get it to work by applying it to the last program i wrote wich is this one:

HTML>
<HEAD>
<TITLE> </TITLE>

<SCRIPT LANGUAGE = "JavaScript">

function clicked(){


if (event.srcElement.style.backgroundColor == "red")
event.srcElement.style.backgroundColor = "white";
else
event.srcElement.style.backgroundColor = "red";
}




</SCRIPT>

</HEAD>

<BODY>
<CENTER>
<TABLE BORDER= "1" HEIGHT= "50%" WIDTH= "50%">

<TR>
<TD ONCLICK="clicked()">&nbsp</TD>
<TD ONCLICK="clicked()">&nbsp</TD>
<TD ONCLICK="clicked()">&nbsp</TD>
</TR>

<TR>
<TD ONCLICK="clicked()">&nbsp</TD>
<TD ONCLICK="clicked()">&nbsp</TD>
<TD ONCLICK="clicked()">&nbsp</TD>
</TR>

<TR>
<TD ONCLICK="clicked()">&nbsp</TD>
<TD ONCLICK="clicked()">&nbsp</TD>
<TD ONCLICK="clicked()">&nbsp</TD>
</TR>


</TABLE>

<INPUT TYPE = "BUTTON" VALUE = "CLICK TO START" ONCLICK = "START()">




</CENTER>

</BODY>

</HTML>
Any help would be greatly appreciated.
Thank you

 
Out of curiosity, what would be the purpose of such a program? I can't see any valid business need for such a thing.

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
[tt]parseInt(math.random() * 3)[/tt] will give you a random integer between 0 and 2 inclusive. So that should help you pick random row/column coordinates for your cell.

[tt]window.setInterval(myFunction, 350)[/tt] will run a function every 350 milliseconds.

Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.

Webflo
 
randomly turn red every 300ms

Not very random then?

--
Tek-Tips Forums is Member Supported. Click Here to donate

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top