• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Get table cell color in Javascript?

igowerf

Diamond Member
I generated a large HTML table of square cells with random colors using PHP.

Now I want the colors to change randomly when the user mouses over the cell, but I'm trying to prevent the new random color to be the same as the old random color.

Here's how I have it set up...

<script type="text/javascript">
var varColors = new Array(5);
varColors[0]="#FF9900";
varColors[1]="#FFFF00";
varColors[2]="#00FFFF";
varColors[3]="#FF0033";
varColors[4]="#FF00FF";

function randomColor(var currentColor)
{
do
{
var ran_number=Math.round(Math.random()*4);
color = varColors[ran_number];
}while (color == currentColor);
return(color);
}
</script>

When I call randomColor() from OnMouseOver, is there any easy way to pass it the current cell color? I know that if I use color GIF's, I can easily do mouseOver's, but I'd like to stick to this method for now. Thanks.
 
within the <td> tag, where I assume you are using bgcolor and the mouseover / mouseout events, you should be able to: "onMouseover(randomColor(this.bgcolor))"
The only problem is to make the color revert to the original one for the onMouseout event.
 
Back
Top