seanpowell
asked on
Multiple rows and heights.
This works for a single row, can it be set for an unkown number of them?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<head>
<title>Tables</title>
<script type="text/javascript">
function sizeRows() {
H = Math.max(document.getEleme ntById('ro w2').offse tHeight,do cument.get ElementByI d('row1'). offsetHeig ht);
document.getElementById('r ow2').styl e.height = H+'px';
document.getElementById('r ow1').styl e.height = H+'px';
}
</script>
</head>
<body onload="sizeRows();">
<table cellspacing="0">
<tr>
<td>
<table id="table1" cellspacing="0">
<tr>
<td id="row1">
Data in Table One <---There could be lots of these...
</td>
</tr>
</table></td>
<td>
<table id="table2" cellspacing="0">
<tr>
<td id="row2"> <---There could be lots of these...
Data in Table Two<br />
Data in Table Two<br />
Data in Table Two<br />
Data in Table Two<br />
</td>
</tr>
</table></td>
</tr>
</table>
</body>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<head>
<title>Tables</title>
<script type="text/javascript">
function sizeRows() {
H = Math.max(document.getEleme
document.getElementById('r
document.getElementById('r
}
</script>
</head>
<body onload="sizeRows();">
<table cellspacing="0">
<tr>
<td>
<table id="table1" cellspacing="0">
<tr>
<td id="row1">
Data in Table One <---There could be lots of these...
</td>
</tr>
</table></td>
<td>
<table id="table2" cellspacing="0">
<tr>
<td id="row2"> <---There could be lots of these...
Data in Table Two<br />
Data in Table Two<br />
Data in Table Two<br />
Data in Table Two<br />
</td>
</tr>
</table></td>
</tr>
</table>
</body>
oops
function sizeRows() {
tb = document.getElementById('t able1');
allCells = new Array()
for (r=0;r<tb.rows.length;r++) {
for (c=0;c<tb.rows[r].cells.le ngth;c++) allCells[allCells.length]= tb.rows[r] .cells[c]. offsetHeig ht
}
H = Math.max(allCells.toString ());
for (r=0;r<tb.rows.length;r++) tb.rows[r].style.height = H+'px';
}
function sizeRows() {
tb = document.getElementById('t
allCells = new Array()
for (r=0;r<tb.rows.length;r++)
for (c=0;c<tb.rows[r].cells.le
}
H = Math.max(allCells.toString
for (r=0;r<tb.rows.length;r++)
}
or something... You named the cell row1 and 2
ASKER
Something's wrong....
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<head>
<title>Tables</title>
<style type="text/css">
table { border: 6px solid blue; }
table td table { border: 3px solid gray; }
table td table td { border: 3px solid black; }
</style>
<script type="text/javascript">
function sizeRows() {
tb = document.getElementById('t able1');
allCells = new Array()
for (r=0;r<tb.rows.length;r++) {
for (c=0;c<tb.rows[r].cells.le ngth;c++) allCells[allCells.length]= tb.rows[r] .cells[c]. offsetHeig ht
}
H = Math.max(allCells.toString ());
for (r=0;r<tb.rows.length;r++) tb.rows[r].style.height = H+'px';
}
</script>
</head>
<body onload="sizeRows();">
<table cellspacing="0">
<tr>
<td>
<table id="table1" cellspacing="0">
<tr>
<td id="row1a">
Data in Table One Row One
</td>
</tr>
<tr>
<td id="row1b">
Data in Table One Row Two
</td>
</tr>
</table></td>
<td>
<table id="table2" cellspacing="0">
<tr>
<td id="row2a">
Data in Table Two Row One<br />
Data in Table Two Row One<br />
Data in Table Two Row One<br />
Data in Table Two Row One<br />
</td>
</tr>
<tr>
<td id="row2b">
Data in Table Two Row Two<br />
Data in Table Two Row Two<br />
Data in Table Two Row Two<br />
Data in Table Two Row Two<br />
</td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
We need to reference the other table somwehere, don't we?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<head>
<title>Tables</title>
<style type="text/css">
table { border: 6px solid blue; }
table td table { border: 3px solid gray; }
table td table td { border: 3px solid black; }
</style>
<script type="text/javascript">
function sizeRows() {
tb = document.getElementById('t
allCells = new Array()
for (r=0;r<tb.rows.length;r++)
for (c=0;c<tb.rows[r].cells.le
}
H = Math.max(allCells.toString
for (r=0;r<tb.rows.length;r++)
}
</script>
</head>
<body onload="sizeRows();">
<table cellspacing="0">
<tr>
<td>
<table id="table1" cellspacing="0">
<tr>
<td id="row1a">
Data in Table One Row One
</td>
</tr>
<tr>
<td id="row1b">
Data in Table One Row Two
</td>
</tr>
</table></td>
<td>
<table id="table2" cellspacing="0">
<tr>
<td id="row2a">
Data in Table Two Row One<br />
Data in Table Two Row One<br />
Data in Table Two Row One<br />
Data in Table Two Row One<br />
</td>
</tr>
<tr>
<td id="row2b">
Data in Table Two Row Two<br />
Data in Table Two Row Two<br />
Data in Table Two Row Two<br />
Data in Table Two Row Two<br />
</td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
We need to reference the other table somwehere, don't we?
tb = document.getElementById('t able1');
references ONE table. I did not see you wanted more than one table
Michel
references ONE table. I did not see you wanted more than one table
Michel
How about:
AllCells = document.getElementsByTagN ame("td"). offsetHeig ht;
H=Math.max(AllCells.toStin g());
for (i=0;i<AllCells.length;i++ )
{
allCells.style.height=H+'p x';
}
Does that work?
Cd&
AllCells = document.getElementsByTagN
H=Math.max(AllCells.toStin
for (i=0;i<AllCells.length;i++
{
allCells.style.height=H+'p
}
Does that work?
Cd&
function sizeRows() {
tbls = document.getElementsByTagN
allCells = new Array()
for (t=0;t<tbls.length;t++) {
for (r=0;r<tbls[t].rows.length
for (c=0;c<tbls[t].rows[r].cel
}
}
H = Math.max(allCells.toString
for (t=0;t<tbls.length;t++) {
for (r=0;r<tbls[t].rows.length
for (c=0;c<tbls[t].rows[r].cel
}
}
}
even better, cobol ;)
ASKER
Hmmm - not yet - AllCells is null or not an object...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<head>
<title>Tables</title>
<style type="text/css">
table { border: 6px solid blue; }
table td table { border: 3px solid gray; }
table td table td { border: 3px solid black; }
</style>
<script type="text/javascript">
function sizeRows() {
var tb = document.getElementById('t able2'), H=0;
for (r=0;r<tb.rows.length;r++) for (c=0;c<tb.rows[r].cells.le ngth;c++) H = Math.max(H,tb.rows[r].cell s[c].offse tHeight);
tb = document.getElementById('t able1')
for (r=0;r<tb.rows.length;r++) for (c=0;c<tb.rows[r].cells.le ngth;c++) tb.rows[r].cells[c].style. height = H+'px';
}
</script>
</head>
<body onload="sizeRows();">
<table cellspacing="0">
<tr>
<td>
<table id="table1" cellspacing="0">
<tr>
<td id="row1a">
Data in Table One Row One
</td>
</tr>
<tr>
<td id="row1b">
Data in Table One Row Two
</td>
</tr>
</table></td>
<td>
<table id="table2" cellspacing="0">
<tr>
<td id="row2a">
Data in Table Two Row One<br />
Data in Table Two Row One<br />
Data in Table Two Row One<br />
Data in Table Two Row One<br />
</td>
</tr>
<tr>
<td id="row2b">
Data in Table Two Row Two<br />
Data in Table Two Row Two<br />
Data in Table Two Row Two<br />
Data in Table Two Row Two<br />
</td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
"http://www.w3.org/TR/html4/strict.dtd">
<head>
<title>Tables</title>
<style type="text/css">
table { border: 6px solid blue; }
table td table { border: 3px solid gray; }
table td table td { border: 3px solid black; }
</style>
<script type="text/javascript">
function sizeRows() {
var tb = document.getElementById('t
for (r=0;r<tb.rows.length;r++)
tb = document.getElementById('t
for (r=0;r<tb.rows.length;r++)
}
</script>
</head>
<body onload="sizeRows();">
<table cellspacing="0">
<tr>
<td>
<table id="table1" cellspacing="0">
<tr>
<td id="row1a">
Data in Table One Row One
</td>
</tr>
<tr>
<td id="row1b">
Data in Table One Row Two
</td>
</tr>
</table></td>
<td>
<table id="table2" cellspacing="0">
<tr>
<td id="row2a">
Data in Table Two Row One<br />
Data in Table Two Row One<br />
Data in Table Two Row One<br />
Data in Table Two Row One<br />
</td>
</tr>
<tr>
<td id="row2b">
Data in Table Two Row Two<br />
Data in Table Two Row Two<br />
Data in Table Two Row Two<br />
Data in Table Two Row Two<br />
</td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
allCells = document.getElementsByTagN
allHeights = new Array()
for (i=0;i<allCells.length;i++
{
allHeights[i] = allCells[i].style.offsetHe
}
H=Math.max(allHeights.toSt
for (i=0;i<allCells.length;i++
{
allCells[i].style.height=H
}
BOO cobol
Sure you missed the typo:
allCells.style.height=H+'p x';
Should be AllCells.
You didn't think would go without a typo just becaue it's Easter.
Cd&
allCells.style.height=H+'p
Should be AllCells.
You didn't think would go without a typo just becaue it's Easter.
Cd&
toSting()
should be
toString()
sorry
should be
toString()
sorry
ASKER
Didn't miss it - didn't work :-)
Still no joy guys...
Still no joy guys...
Oh that too....
allHeights[i] = allCells[i].style.offsetHe ight
?
I think:
allHeights[i] = allCells[i].offsetHeight
offsetHeight is not part of the style object
Cd&
allHeights[i] = allCells[i].style.offsetHe
?
I think:
allHeights[i] = allCells[i].offsetHeight
offsetHeight is not part of the style object
Cd&
ASKER
Invalid argument Michel...
So far I have this:
<script type="text/javascript">
function sizeRows() {
allCells = document.getElementsByTagN ame("td")
allHeights = new Array()
for (i=0;i<allCells.length;i++ )
{
allHeights[i] = allCells[i].style.offsetHe ight
}
H=Math.max(allHeights.toSt ring());
for (i=0;i<allCells.length;i++ )
{
allCells[i].style.height=H +'px';
}
}
</script>
So far I have this:
<script type="text/javascript">
function sizeRows() {
allCells = document.getElementsByTagN
allHeights = new Array()
for (i=0;i<allCells.length;i++
{
allHeights[i] = allCells[i].style.offsetHe
}
H=Math.max(allHeights.toSt
for (i=0;i<allCells.length;i++
{
allCells[i].style.height=H
}
}
</script>
ASKER
And now this, still invalid argument:
<script type="text/javascript">
function sizeRows() {
allCells = document.getElementsByTagN ame("td")
allHeights = new Array()
for (i=0;i<allCells.length;i++ )
{
allHeights[i] = allCells[i].offsetHeight
}
H=Math.max(allHeights.toSt ring());
for (i=0;i<allCells.length;i++ )
{
allCells[i].style.height=H +'px';
}
}
</script>
<script type="text/javascript">
function sizeRows() {
allCells = document.getElementsByTagN
allHeights = new Array()
for (i=0;i<allCells.length;i++
{
allHeights[i] = allCells[i].offsetHeight
}
H=Math.max(allHeights.toSt
for (i=0;i<allCells.length;i++
{
allCells[i].style.height=H
}
}
</script>
sean,
I tested mine & it does work... the cells in the first table are a bit higher than the second because of the borders... offsetHeight includes the borders wheras style.height does not. If you don't plan on having a border, the code I posted will work. If you do, let me know & I'll adjust the code to account for the border.
I tested mine & it does work... the cells in the first table are a bit higher than the second because of the borders... offsetHeight includes the borders wheras style.height does not. If you don't plan on having a border, the code I posted will work. If you do, let me know & I'll adjust the code to account for the border.
ASKER
I think brgivens is pretty close, except it appears to make the 1 and 3 the same, as opposed to 1 and 2:
Table cells:
1 2
3 4
1 should be the same height as 2, and 3 should be the same height as 4...
Table cells:
1 2
3 4
1 should be the same height as 2, and 3 should be the same height as 4...
ASKER
ASKER
Other version is here:
http://www.pdgmedia.com/ee/1d.html
http://www.pdgmedia.com/ee/1d.html
This?
function sizeRows() {
var tb = document.getElementById('t able2'), H=0;
for (r=0;r<tb.rows.length;r++) for (c=0;c<tb.rows[r].cells.le ngth;c++) document.getElementById('t able1').ro ws[r].cell s[c].style .height = tb.rows[r].cells[c].offset Height + "px";
}
function sizeRows() {
var tb = document.getElementById('t
for (r=0;r<tb.rows.length;r++)
}
ASKER
That seems to do the trick, uless there's any padding in the cells:
http://www.pdgmedia.com/ee/1e.html
So we just need to add the padding to the statement, whatever it's set at. Correct?
http://www.pdgmedia.com/ee/1e.html
So we just need to add the padding to the statement, whatever it's set at. Correct?
ASKER
ASKER
Interesting - Moz has no problem calculating the padding - just IE...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That seems to have nailed it:-)
Thanks all, and have a Happy Egg!
Thanks all, and have a Happy Egg!
I should've simplified that:
function sizeRows() {
var c, tb1 = document.getElementById('t able1'), tb2 = document.getElementById('t able2'), o, p, r;
for (r=0;r<tb2.rows.length;r++ ) for (c=0;c<tb2.rows[r].cells.l ength;c++) {(o=tb1.rows[r].cells[c]). style.heig ht = (p=tb2.rows[r].cells[c]).o ffsetHeigh t + "px"; o.style.height = (2 * p.offsetHeight - o.offsetHeight) + "px";}
}
function sizeRows() {
var c, tb1 = document.getElementById('t
for (r=0;r<tb2.rows.length;r++
}
Glad I could help :)
Happy "Egg" 2 all 2!
Happy "Egg" 2 all 2!
function sizeRows() {
tb = document.getElementById('t
allCells = new Array()
for (r=0;r<tb.rows.length;r++)
for (c=0;c<tb.rows[r].cells.le
}
H = Math.max(allCells.toString
for (r=0;r<tb.rows.length;r++)
for (c=0;c<tb.rows[r].cells.le
}
}