Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change background color of 2 TD's on MouseOver

Status
Not open for further replies.

lesleint

IS-IT--Management
Apr 11, 2003
144
US
I am trying to create this function but keep getting JS errors. Can someone please point me in the righ tdirection.
Here is the JS functions
Code:
<script language=&quot;JavaScript&quot;>
function rollOver(td1ID,td2ID)
{
document.getElementById('td1ID').style.backgroundColor = '#FFFFFF';
document.getElementById('td2ID').style.backgroundColor = '#B0D0E7';
}
function rollOut(td1ID,td2ID)
{
document.getElementById('td1ID').style.backgroundColor = '#B0D0E7';
document.getElementById('td2ID').style.backgroundColor = '#FFFFFF';
}
</script>

And here is my HTML

Code:
<table border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;>
  <tr onMouseOver=&quot;rollOver('menu1a','menu2a');&quot; onMouseOut=&quot;rollOut('menu1a','menu2a');&quot;>
    <td style=&quot;width:29px;background-color:#B0D0E7;&quot; id=&quot;menu1a&quot;> </td>
    <td style=&quot;width:200px;background-color:#FFFFFF;&quot; id=&quot;menu2a&quot;> </td>
  </tr>
</table>
 
This works fine. Notice that I removed the single quotes from your function:
<Html><head>
<script language=&quot;JavaScript&quot;>
function rollOver(td1ID,td2ID)
{
document.getElementById(td1ID).style.backgroundColor = '#FFFFFF';
document.getElementById(td2ID).style.backgroundColor = '#B0D0E7';
}
function rollOut(td1ID,td2ID)
{
document.getElementById(td1ID).style.backgroundColor = '#B0D0E7';
document.getElementById(td2ID).style.backgroundColor = '#FFFFFF';
}
</script>
</head><body>
<table border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;>
<tr onMouseOver=&quot;rollOver('menu1a','menu2a');&quot; onMouseOut=&quot;rollOut('menu1a','menu2a');&quot;>
<td style=&quot;width:29px;background-color:#B0D0E7;&quot; id=&quot;menu1a&quot;>  </td>
<td style=&quot;width:200px;background-color:#FFFFFF;&quot; id=&quot;menu2a&quot;>  </td>
</tr>
</table>
</body>
</html>
 
Thanks, I am just starting to get into writing JS
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top