Javascript Change Table Row Color
I have a simple Javascript that changes the background color of the table row you click on and then switches it back when you click on a different one.
Here is the relevant code:
Code:
<script language="JavaScript">
function toggle(x,origColor){
var newColor = 'red';
if ( x.style ) {
x.style.backgroundColor = (newColor == x.style.backgroundColor)? origColor : newColor;
}
}
</script>
And the relevant HTML:
Code:
<table width=700 border=0 cellpadding=0 cellspacing=0 >
<tr id='1' style="background-color: #FFFFCC>
<td>
<a href=# onFocus="toggle(document.getElementById('1'),'#FFFFCC');" onBlur="toggle(document.getElementById('1'),'#FFFFCC');">
<img name="View1" border="0" src="images/view.gif">
</a>
</td>
</tr>
<tr id='2' style="background-color: #FFFFFF>
<td>
<a href=# onFocus="toggle(document.getElementById('2'),'#FFFFCC');" onBlur="toggle(document.getElementById('2'),'#FFFFCC');">
<img name="View2" border="0" src="images/view.gif">
</a>
</td>
</tr>
<tr id='3' style="background-color: #FFFFCC>
<td>
<a href=# onFocus="toggle(document.getElementById('3'),'#FFFFCC');" onBlur="toggle(document.getElementById('3'),'#FFFFCC');">
<img name="View3" border="0" src="images/view.gif">
</a>
</td>
</tr>
</table>
This repeates for several hundred rows (PHP+MySQL).
So my problem is not with the above code, it works perfect. But in my javascript I am using the alternate color as "red". If I try and use something like "#FFFF00" it breaks it.
Any suggestions?
David