Click to See Complete Forum and Search --> : How do I compute the height of a textarea
scottsplace
03-21-2003, 12:27 PM
Given the number of rows, and that no fontSize is assigned to this or any of it's parents (uses browser default).
How do I compute the height of the text value (may be more or less than the textarea height).
Thanks,
Scott!
khaki
03-21-2003, 01:50 PM
Hi Scott...
Are you asking how to determine the users default font type AND size so that you can calculate the pixel hieght of the entire text-area?
(if so... that's a really good question. LOL!)
Otherwise... just set the font type and size yourself - and then calculate it for yourself (unless someone has already worked-out a table that provides such things. ???).
You also need to factor-in the assigned width value. (ugh... math!)
Plus... I would think that even if you could calculate all of these things, cross-browser interpretation may(?) toss the whole issue into further chaos :eek: .
And that's not even to take into account the actual characters that could be in the textarea (10 "I"s and 10 "M"s do not use the same amount of space! Yikes!
Hey... if your looking to give yourself a head-ache (and it seems like you are. lol), just do what I did ealier this week... delete Internet Explorer and reboot! Best darn head-ache you'll ever have... LOL!!!
pretty curious as to why you are trying to figure this out though...
k
scottsplace
03-21-2003, 05:16 PM
I'm trying to create a "printable" view of a web page. The textarea's on these pages have a fixed width, but to make them "printable", the height needs to be adjusted based on the amount of text - some bigger, some smaller.
I was also considering moving the textarea text into a table cell of the same width, which should automatically size heightwize. But I still need to know how high that is, because the elements below, which have absolute coordinates, need to be move down.
Scott!
khalidali63
03-21-2003, 05:30 PM
Suppose you have id attribute set for your textarea
say "ta"
now var obj = document.getElementById("ts")
now
height = obj.offsetHeight;
width = obj.offsetWidth
should give you the required info...
Cheers
Khalid
scottsplace
03-21-2003, 07:39 PM
Okay, I see now.
I was using 'cloneNode' to create a duplicate node. In this case offsetHeight = 0 util appendChild is performed. It also turns out that if I create a table with a single cell and put the textarea text inside, I can get the true height (after appendChild, that is).
Case solved. Thanks for your help.
Scott!