How can I set a textarea to be as tall as its container allows i.e. to
be 100% high? (The container is liquid.) I've tried CSS but to no avail
so I'm hoping there's a way to script it.
Andrew Poulos
If the markup looks something like this:
<div style="border:solid 1px;position:relative;height:50%">
<textarea id="edit" style="border:none;position:absolute;top:0;margin:
0"></textarea>
</div>
Then the script looks like this:
function windowSize() {
var el = document.getElementById('edit');
if (el) {
var c = el.parentNode;
if (c && typeof(c.offsetHeight) != 'undefined' && c.offsetHeight >
1)
el.style.height = (c.offsetHeight - 2) + 'px' // adjusted for 1px
border on container
}
}
if (document.getElementById) {
window.onresize = windowSize;
window.onload = windowSize;
}
If you change the border widths of either element or the top and/or
margin of the textarea, you will have to change the commented line in
the script to compensate.
Tested in IE6/7, Opera 9, the latest Firefox and Netscape, Netscape
6.2 and the Windows Safari Beta.