[thelist] JavaScript: How to save/return state on group of objects

Tom Dell'Aringa pixelmech at yahoo.com
Thu Nov 13 13:27:01 CST 2003


Hi there,

I have a table of data that is styled with various background colors.
Any one cell can be one of 5 colors - 2 shades of yellow, 2 shades of
green or black.

I have a function where you rollover the row, I highlight that row so
it is more easily readable.

PROBLEM: Highlighting the row is easy, returning each cell back to
its' one of 5 colors is not so easy. This is what I want to do.

Here is my highlight function (which is set via an init() function
during onload):

function HLRow()
{
	var table = document.getElementById("schedTable");
	var oRows = table.getElementsByTagName("TR");
	
	var lastRowClass;
	
	for(var i=0; i<oRows.length; i++)
	{
		oRows[i].onmouseover = function() {
			BoldRow_HLCells(this);
			this.style.fontWeight = "bold";
			this.style.color = "#cc0000";
		}
		oRows[i].onmouseout = function() {
			BoldRow_ResetCells(this);
			this.style.fontWeight = "normal";
			this.style.color = "#000";
		}
	}
}

You can see I am calling 2 other functions within, one to highlight
the row, one to reset the row back to its colors - that's where I
need the help. Those two functions are nearly identical:

function BoldRow_HLCells (oRow) {
	var oCells = oRow.getElementsByTagName("TD");
	for(var i=0; i<oCells.length; i++)
	{
		oCells[i].style.backgroundColor="#66cc99";
	}
}

function BoldRow_ResetCells (oRow) {
	var oCells = oRow.getElementsByTagName("TD");
	for(var i=0; i<oCells.length; i++)
	{
		oCells[i].style.backgroundColor="#fff";
	}
}

This all works, but of course returning the cells to white is not
what I want :). My first thought was to save each cell's original
value in an array, then run through that array and reset them all.
I'm just wondering if there is a better way.

I can almost see Marcus now typing up an OO answer...;)

You can see the page in its full glory at:

http://www.pixelmech.com/review/newWorkerTable.html

TIA

Tom

=====
http://www.pixelmech.com/ :: Web Development Services
http://www.DMXzone.com/ :: JavaScript Author / Every Friday!
http://www.thywordistruth.net/ :: Eternal Life

"I'll ho ho and ha ha you!" (Daffy Duck)


More information about the thelist mailing list