Resizing table height

  • Thread starter Thread starter JMT
  • Start date Start date
J

JMT

Hello,

I get some dynamic controls (ASP .Net) inside a table, the height
property of the table is variable according the controls loaded, so I
need to know the final table height, this value must be an odd number
by graphic design. I put the next code at bottom of the page;


<script type="text/javascript" language="JavaScript1.2">


if (document.getElementById("TABLE1").clientHeight%2 == 0)
document.getElementById("TABLE1").height =
document.getElementById("TABLE1").clientHeight + 1;

</script>


Works fine in IE6 & IE7, in Firefox 2 and Opera 9 doesn't works, I've
checked with alert(document.getElementById("TABLE1").height)
and I can see the result desired, but the height of the table remains
and doesn't change in the page. ¿Is there any solution for it works
in Firefox and Opera?


Many thanks.
 
JMT said:
Hello,

I get some dynamic controls (ASP .Net) inside a table, the height
property of the table is variable according the controls loaded, so I
need to know the final table height, this value must be an odd number
by graphic design. I put the next code at bottom of the page;


<script type="text/javascript" language="JavaScript1.2">


if (document.getElementById("TABLE1").clientHeight%2 == 0)
document.getElementById("TABLE1").height =
document.getElementById("TABLE1").clientHeight + 1;

</script>


Works fine in IE6 & IE7, in Firefox 2 and Opera 9 doesn't works, I've
checked with alert(document.getElementById("TABLE1").height)
and I can see the result desired, but the height of the table remains
and doesn't change in the page. ¿Is there any solution for it works
in Firefox and Opera?


Many thanks.

There is no height property for the table tag, that's why it doesn't
work in standards compliant browsers. When you set the height property,
a new member is created in the table object, but it's not used for anything.

Use the style.height property to set the height of the table. Don't
forget to append the 'px' unit when you set the value.
 
Thank you Göran, now it works!

if (document.getElementById("TABLE1").clientHeight%2 == 0)
document.getElementById("TABLE1").style.height =
parseInt(document.getElementById("TABLE1").clientHeight + 1) + 'px';

Regards.
 
Back
Top