Forum Moderators: phranque
function initresultDiv() {
var ht = document.getElementById("headertable");
var bt = document.getElementById("bodytable");
var htr = ht.rows[0];
var btr = bt.rows[0];
var btrlen = btr.cells.length;
for (var i=0; i<btrlen; i++) {
htr.cells[i].style.width = btr.cells[i].offsetWidth;
}
}
The jscript above does go an reformat the header table, but only somewhat, and not nearly enough. The problem is body content varies in size, so I want the header table THs to match the body table TDs.
Anyone have any better luck with this sort of trickery? (Apparently NS supports a scrollable tbody, but I'm in an IE web app)
<script>
function pageInit() {
var tmr1 = setInterval("showsize()", 30);
var tmr2 = setInterval("resize()", 20);
}function showsize() {
var t = document.getElementById("tt");
var t2 = document.getElementById("tt2");
txti[0].value = t.offsetWidth;
txti[1].value = t.rows[0].cells[0].offsetWidth;
txti[2].value = t.rows[0].cells[1].offsetWidth;
txti[3].value = t.rows[0].cells[2].offsetWidth;
txti[4].value = t.rows[0].cells[3].offsetWidth;
}
function resize() {
var t = document.getElementById("tt");
var t2 = document.getElementById("tt2");
t2.rows[0].cells[0].width = t.rows[0].cells[0].offsetWidth;
t2.rows[0].cells[1].width = t.rows[0].cells[1].offsetWidth;
t2.rows[0].cells[2].width = t.rows[0].cells[2].offsetWidth;
t2.rows[0].cells[3].width = t.rows[0].cells[3].offsetWidth;
}
</script>
<style>
table { background-color:#a000a0; }
td { border:1px solid white; }
table#tt2 td { background-color:#00a000; }
</style>
<body onload="pageInit();">
<label for="txti">Table:</label><input id="txti"><br>
<label for="txti">TD1:</label><input id="txti">
<label for="txti">TD2:</label><input id="txti">
<label for="txti">TD3:</label><input id="txti">
<label for="txti">TD4:</label><input id="txti">
<table width="100%" id="tt">
<tr>
<td> </td>
<td> asd</td>
<td> </td>
<td> </td>
</tr>
</table>
<table id="tt2">
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
</body>
(of course, then wrap the "body" table in a scrolling div)