Forum Moderators: open

Message Too Old, No Replies

Finding Table And Cell Dimensions With Javascript

         

brendan3eb

4:11 am on Feb 8, 2005 (gmt 0)

10+ Year Member



I have an expandable table that I want to find the dimensions of so I can decide on how large to make the dimensions of the table underneath it. Is there a way to detect the dimensions of a table or cell with javascript?

SpaceFrog

8:38 am on Feb 8, 2005 (gmt 0)

10+ Year Member



I guess your are looking for something like this:


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>one</title>
<style type='text/css'>
td.headcol {width:auto;}
</style>
</head>
<body>
<div style="width:100%;overflow:auto;">
<table border="1" style="width:100%;overflow:hidden;">
<tr colspan=5>
<td class='headcol' id='col1'>one</td>
<td class='headcol' id='col2'>two</td>
<td class='headcol' id='col3'>three</td>
<td class='headcol' id='col4'>four</td>
<td style="width:10px;"></td>
</tr>
</table>
<div>
<div style="width:100%;height:200px;overflow-Y:auto;">
<table border="1" style="width:100%;overflow:hidden">
<script type='text/javascript'>
//SpaceFrog 2005
var largcol = new Array()
for (i=1;i<5;i++){
largcol[i]=parseInt(document.getElementById('col'+i).offsetWidth)-3 + "px";
}
for (i=0;i<55;i++){
document.write("\<tr\>\<td style='width:"+largcol[1]+"'\>dsfqsdfsdd dsqf qsdf sdqf sqdf qsdf sdf &nbsp;\<\/td\>\<td style='width:"+largcol[2]+"'\>two\<\/td\>\<td style='width:"+largcol[3]+"'\>three\<\/td\>\<td style='width:"+largcol[4]+"'\>four\<\/td\>\<\/tr\>")
}
</script>
</table>
<div>

</body>

</html>