Jump to content

change background color in table from 2nd row onwards?


sayedsohail

Recommended Posts

Hi everyone,

 

I got a small problem, i am displaying data in a html table with five rows of five columns each, the first row is a title row with blue background, and the 2nd row onwards is the data rows with a radio button.

 

When a user click first row, nothing should happend, but when the user clicks the radio button or any column of the row, I wish to select the radio value (clicked) and set the background color to silver for the entire row of five columns.

 

Here is my javascript code which is working fine, except it removed the first row style background color, which I don't wish to remove.  any suggestions would be highly appreciated. 

 

 

 

var trs = document.getElementsByTagName('tr');

function color(obj)
{
    for(var i=0; i < trs.length; i++)
    {
        var cells = trs[i].getElementsByTagName('td');
        for(var p=0; p < cells.length; p++)
        {
              cells[p].style.backgroundColor='white';
        }
    }
    currentCells = obj.getElementsByTagName('td');
    for(var n=0;n<currentCells.length;n++)
    {
        currentCells[n].style.backgroundColor = 'silver';
    }
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.