Click to See Complete Forum and Search --> : assign variable to store table cell info


gerbilremedy
02-19-2003, 07:45 PM
Hi,

I have created a table to act as a grid of many small squares, each of which changes colour upon mouseover. To do this I have had to use the following html code.

<tr height = 18>

<td width = 18 bgcolor="#FFFFFF" onMouseOver="this.bgColor='#257F00'" onMouseOut="this.bgColor='#FFFFFF'">&nbsp</td>

<td width = 18 bgcolor="#FFFFFF" onMouseOver="this.bgColor='#257F00'" onMouseOut="this.bgColor='#FFFFFF'">&nbsp</td>


and repeate this over and over for each row (which is very tedious)


How do assign the repetition of .<td width = 18 bgcolor="#FFFFFF" onMouseOver="this.bgColor='#257F00'" onMouseOut="this.bgColor='#FFFFFF'">&nbsp</td> to a variable? And once I have done this, how do I call this variable for use in the table.

Thanks

gerbilremedy
02-19-2003, 10:21 PM
How do I get this running as a free standing application (ie what html do I need to add so that I can get the code running in IE). Sorry, I am pretty new to this stuff.

gerbilremedy
02-19-2003, 10:48 PM
sorry but can you give me an example of this in action?

gerbilremedy
02-19-2003, 11:04 PM
<table border= 0 align="center"bgcolor="#006600" >

<tr height = 18>

<td width = 18 tbl </td>
<td width = 18 tbl</td>
<td width = 18 tbl</td>
<td width = 18 tbl </td>
</tr>
</table>


<BODY>
<script language="JavaScript" type="text/javascript">


var tbl = document.getElementById("myTableID");
var row, cell, len2, len = tbl.rows.length;
for (row=0; row<len; row++) {
len2 = tbl.rows[row].cells.length;
for (cell=0; cell<len2; cell++) {
tbl.rows[row].cells[cell].onmouseover = function() {
this.bgColor = "#257F00";
return true;
}
tbl.rows[row].cells[cell].onmouseout = function() {
this.bgColor = "#FFFFFF";
return true;
}
}
}


</script>
</BODY>







WHAT DO I DO TO FIX IT.....I've got this so far