stevesimo Posted January 21, 2008 Share Posted January 21, 2008 Hi, I am trying to change the colour of a table background from white to red using javascript. I have attached an onmouseover event to a link so that when you move over the link the table background colour will change to red. I keep getting a script error message saying that an object is required but not sure what this means. here is my code: <script language="JavaScript"> function changeTableBackground(){ if(document.getElementsByTagName){ var mytable = document.getElementById(theTable); mytable.style.background = '#ff0000'; } } </script> <table width="600" height="400" align="center" border="1" id="theTable"> <tr><td></td></tr> </table> <br> <a href="#" onMouseOver="changeTableBackground()">Change Table Background</a> [code] any help appreciated thanks, steve [/code] Link to comment https://forums.phpfreaks.com/topic/87096-solved-change-table-background-colour-using-javascript/ Share on other sites More sharing options...
rhodesa Posted January 21, 2008 Share Posted January 21, 2008 try changing it to this: var mytable = document.getElementById('theTable'); Link to comment https://forums.phpfreaks.com/topic/87096-solved-change-table-background-colour-using-javascript/#findComment-445435 Share on other sites More sharing options...
stevesimo Posted January 21, 2008 Author Share Posted January 21, 2008 It works! Thanks for your help Steve Link to comment https://forums.phpfreaks.com/topic/87096-solved-change-table-background-colour-using-javascript/#findComment-445440 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.