Click to See Complete Forum and Search --> : Obtaining <TD> cell width in a javascript when using "%" of screen option


schaferkj
12-29-2002, 01:25 AM
I have looked through the JavaScript Goodies book and have found how to reference the size of a <IMG> tag. I want to grab the width/height of a percentage defined table/cell and then take that value to define the picture length. I am trying to have the images resize when the browser/table resizes. But, I am having difficulty obtaining the actual value that is assigned. I have named the cell and used document.cellname to try to reference it to no avail. Any suggestions?

Thanks,
Ken

khalidali63
12-29-2002, 10:31 AM
Method below will worj for both NS6+ and IE5+ browsers

<body >

<table id="myTable" width="50%" height="50%" border="2">
<tr>
<td width="30%" height="30%" align="center">&nbsp;</td>
<td width="40%" height="30%" align="center">&nbsp;</td>
<td width="30%" height="30%" align="center">&nbsp;</td>
</tr>
<tr>
<td width="30%" height="40%" align="center">&nbsp;</td>
<td width="40%" height="40%" align="center">&nbsp;</td>
<td width="30%" height="40%" align="center">&nbsp;</td>
</tr>
<tr>
<td width="30%" height="30%" align="center">&nbsp;</td>
<td width="40%" height="30%" align="center">&nbsp;</td>
<td width="30%" height="30%" align="center">&nbsp;</td>
</tr>
</table>

<script>
onload = parseHTML
function parseHTML(){
var tds = document.getElementsByTagName("td");
for(x=0;x<tds.length;x++){
var td = tds.item(x);
var width = td.width
var nw = width.substring(0,width.indexOf("%"));
nw = (parseInt(nw)+10+"%");
td.setAttribute("width",nw);
}

}

</script>

</body>

Khalid