Entry
How do change the background row colors of a table dynamically? (Upon page load)
Apr 9th, 2008 20:31
ha mo, Dave Clark, Irena,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Irena,
The following code can be used, upon page load, to change the
background row colors of a table:
var color_control = -1;
function AlternateColors(color1, color2)
{
return (++color_control % 2 == 0) ? color1 : color2;
}
function SetRowColors()
{
var row = document.getElementById('dynatable').rows;
var r, len = row.length;
for (r=0; r<len; ++r)
{
row[r].style.backgroundColor = AlternateColors('blue', 'yellow');
}
return true;
}
window.onload = SetRowColors;
Take care,
Dave Clark
www.DaveClarkConsulting.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
http://www.businessian.com
http://www.healthinhealth.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com