Hello
I have searched this forum for a post on how to change the backgroundcolor of the tr-tag in a table. but no luck.
I have found alot on changing the background but none that has helped me.
Im creating a system using ASP.NET and javascripts and my tables are created by webcontrol that i have created.
I have this function below that is called by onclick in the tr.
I have tried to make it dynamic so that all my tables can call it without me having to write special cases for each table.
(The problem is that it only changes the color of the first cell to blue and when i click on another cell it doesnt change the color of the first cell back to white, so now both rows have their first cell colored blue.) (I think it has something to do with my stylesheet)
I have now alterd the webcontrol to also add the class=… to the first <td> and now no cells are changin color!!
I thought that a style in a tr had higher priority than a css??
Oooops. It seems that I am setting the backcolor on each <td> with css and then I dont think it will help to change the backcolor on the <tr>.
Hmmmm. how do i change my function to override each <td>-style?? Do i have to change the backcolor of each <td>?? but I still want each <td> to use the settings in my css, except for the backcolor. and when i click on another row i want the previous to go back and use only the settings in my css.
any ideas.
[code]
function changecolor(Row)
{
var introw;
//show id for the row
//alert(Row.id);
//get the row-nr and add 1 for the header
var rownr=parseFloat(Row.id.substring(Row.id.indexOf(“_”)+2,Row.length)) + 1;
//alert(rownr);
//get the id for the table, (each rows id = table_r + index)
var index=Row.id.indexOf(“_”);
var tbl=Row.id.substring(0,index);
//how many rows has the table
var introw = document.getElementById(tbl).rows.length;
//alert(introw);
//change color to white
for(i=1;i<document.getElementById(tbl).rows.length – 1; i++)
{
//document.getElementById(tbl).rows[i].bgcolor = “#ffffff”;
document.getElementById(tbl).rows(i).style.backgroundColor=”#ffffff”;
//alert(document.getElementById(tbl).rows[i].bgcolor);
}
//change color to blue on clicked row
//document.getElementById(tbl).rows[rownr].backgroundColor = “#99cccc”;
document.getElementById(Row.id).style.backgroundColor=”#99cccc”;
//alert(Row.id + ” ” + document.getElementById(tbl).rows[rownr].bgColor);
}
<table ID=’tbllvwGrade’ width=’100%’ height=’100%’ cellspacing=’0′ cellpadding=’0′>
<THEAD>
<tr ID=”tblheader” style=”top:expression(document.getElementById(‘tbllvwGrade_Header’).scrollTop);position:relative;”>
<td class=’header’ width=’5′> </td>
<td class=’header’>Source</td>
<td class=’header’>GradeNo</td>
<td class=’header’>SteelName</td>
<td class=’header’>Revision</td>
<td class=’header’>C </td>
<td class=’header’>N </td>
<td class=’header’>Cr</td>
<td class=’header’>Ni</td>
<td class=’header’>Mo</td>
<td class=’header’>Others</td>
</tr>
</THEAD>
<TBODY>
<tr ID=tbllvwGrade_r0 onclick=’javascript:changecolor(this)’>
<td width=’5′></td>
<td ID=tbllvwGrade_r0_c0 class=’listbody’></td>
<td ID=tbllvwGrade_r0_c1 class=’listbody’>N08020</td>
<td ID=tbllvwGrade_r0_c2 class=’listbody’></td>
<td ID=tbllvwGrade_r0_c3 class=’listbody’></td>
<td ID=tbllvwGrade_r0_c4 class=’listbody’><0.07</td>
<td ID=tbllvwGrade_r0_c5 class=’listbody’>19.0-21.0</td>
<td ID=tbllvwGrade_r0_c6 class=’listbody’>32.0-38.0</td>
<td ID=tbllvwGrade_r0_c7 class=’listbody’>2.00-3.00</td>
<td ID=tbllvwGrade_r0_c8 class=’listbody’>Cu:3.0-4.0 Mn:<2.00 Nb:8xC-1.00 P :<0.045 S :<0.035 Si:<1.00 </td>
<td style=’display:none’>
<input ID=’hdnID’ type=’hidden’ value=”></td>
<td style=’display:none’><input ID=’hdnKey’ type=’hidden’ value=’79356key’>
</td>
</tr>
<tr ID=tbllvwGrade_r1 onclick=’javascript:changecolor(this)’>
<td width=’5′></td>
<td ID=tbllvwGrade_r1_c0 class=’listbody’></td>
<td ID=tbllvwGrade_r1_c1 class=’listbody’>N08367</td>
<td ID=tbllvwGrade_r1_c2 class=’listbody’></td>
<td ID=tbllvwGrade_r1_c3 class=’listbody’></td>
<td ID=tbllvwGrade_r1_c4 class=’listbody’><0.030</td>
<td ID=tbllvwGrade_r1_c5 class=’listbody’>0.18-0.25</td>
<td ID=tbllvwGrade_r1_c6 class=’listbody’>20.0-22.0</td>
<td ID=tbllvwGrade_r1_c7 class=’listbody’>23.5-25.5</td>
<td ID=tbllvwGrade_r1_c8 class=’listbody’>6.0-7.0</td>
<td ID=tbllvwGrade_r1_c9 class=’listbody’>Cu:<0.75 Mn:<2.00 P :<0.040 S :<0.030 Si:<1.00 </td>
<td style=’display:none’><input ID=’hdnID’ type=’hidden’ value=”></td>
<td style=’display:none’><input ID=’hdnKey’ type=’hidden’ value=’79577key’></td>
</tr>
<tr ID=tbllvwGrade_r2 onclick=’javascript:changecolor(this)’>
<td width=’5′></td>
<td ID=tbllvwGrade_r2_c0 class=’listbody’></td>
<td ID=tbllvwGrade_r2_c1 class=’listbody’>N08800</td>
<td ID=tbllvwGrade_r2_c2 class=’listbody’>800</td>
<td ID=tbllvwGrade_r2_c3 class=’listbody’></td>
<td ID=tbllvwGrade_r2_c4 class=’listbody’><0.10</td>
<td ID=tbllvwGrade_r2_c5 class=’listbody’>19.0-23.0</td>
<td ID=tbllvwGrade_r2_c6 class=’listbody’>30.0-35.0</td>
<td ID=tbllvwGrade_r2_c7 class=’listbody’>Al:0.15-0.60 Cu:<0.75 Fe:>39.5 Mn:<1.50 P :<0.045 S :<0.015 Si:<1.00 Ti:0.15-0.60 </td>
<td style=’display:none’><input ID=’hdnID’ type=’hidden’ value=”></td>
<td style=’display:none’><input ID=’hdnKey’ type=’hidden’ value=’79159key’></td>
</tr>
<tr ID=tbllvwGrade_r3 onclick=’javascript:changecolor(this)’>
<td width=’5′></td>
<td ID=tbllvwGrade_r3_c0 class=’listbody’></td>
<td ID=tbllvwGrade_r3_c1 class=’listbody’>N08810</td>
<td ID=tbllvwGrade_r3_c2 class=’listbody’>800H</td>
<td ID=tbllvwGrade_r3_c3 class=’listbody’></td>
<td ID=tbllvwGrade_r3_c4 class=’listbody’>0.05-0.10</td>
<td ID=tbllvwGrade_r3_c5 class=’listbody’>19.0-23.0</td>
<td ID=tbllvwGrade_r3_c6 class=’listbody’>30.0-35.0</td>
<td ID=tbllvwGrade_r3_c7 class=’listbody’>Al:0.15-0.60 Cu:<0.75 Fe:>39.5 Mn:<1.50 P :<0.045 S :<0.015 Si:<1.00 Ti:0.15-0.60 </td>
<td style=’display:none’><input ID=’hdnID’ type=’hidden’ value=”></td>
<td style=’display:none’><input ID=’hdnKey’ type=’hidden’ value=’79160key’></td>
</tr>
<tr ID=tbllvwGrade_r4 onclick=’javascript:changecolor(this)’>
<td width=’5′></td>
<td ID=tbllvwGrade_r4_c0 class=’listbody’></td>
<td ID=tbllvwGrade_r4_c1 class=’listbody’>N08811</td>
<td ID=tbllvwGrade_r4_c2 class=’listbody’>800HT</td>
<td ID=tbllvwGrade_r4_c3 class=’listbody’></td>
<td ID=tbllvwGrade_r4_c4 class=’listbody’>0.06-0.10</td>
<td ID=tbllvwGrade_r4_c5 class=’listbody’>19.0-23.0</td>
<td ID=tbllvwGrade_r4_c6 class=’listbody’>30.0-35.0</td>
<td ID=tbllvwGrade_r4_c7 class=’listbody’>Al:0.15-0.60 Cu:<0.75 Fe:>39.5 Mn:<1.5 P :<0.04 S :<0.015 Si:<1.0 Ti:0.15-0.60 </td>
<td style=’display:none’><input ID=’hdnID’ type=’hidden’ value=”></td>
<td style=’display:none’><input ID=’hdnKey’ type=’hidden’ value=’79161key’></td>
</tr>
<tr ID=tbllvwGrade_r5 onclick=’javascript:changecolor(this)’>
<td width=’5′></td>
<td ID=tbllvwGrade_r5_c0 class=’listbody’></td>
<td ID=tbllvwGrade_r5_c1 class=’listbody’>N08904</td>
<td ID=tbllvwGrade_r5_c2 class=’listbody’>904L</td>
<td ID=tbllvwGrade_r5_c3 class=’listbody’></td>
<td ID=tbllvwGrade_r5_c4 class=’listbody’><0.020</td>
<td ID=tbllvwGrade_r5_c5 class=’listbody’><0.10</td>
<td ID=tbllvwGrade_r5_c6 class=’listbody’>19.0-23.0</td>
<td ID=tbllvwGrade_r5_c7 class=’listbody’>23.0-28.0</td>
<td ID=tbllvwGrade_r5_c8 class=’listbody’>4.0-5.0</td>
<td ID=tbllvwGrade_r5_c9 class=’listbody’>Cu:1.00-2.00 Mn:<2.00 P :<0.045 S :<0.035 Si:<1.00 </td>
<td style=’display:none’><input ID=’hdnID’ type=’hidden’ value=”></td>
<td style=’display:none’><input ID=’hdnKey’ type=’hidden’ value=’79535key’></td>
</tr>
</TBODY>
<TFOOTER><tr ID=”tblfooter”><td></td></tr></TFOOTER>
</table>