Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Matching textarea size to window 1

Status
Not open for further replies.

OsakaWebbie

Programmer
Joined
Feb 11, 2003
Messages
628
Location
JP
I want to create a child window for editing the content of the parent, with a big textarea that will fill as much of the window as possible (except for a little spot for Apply and Reset buttons). The problem is that window sizes are in pixels, but textarea sizes are in rows and cols. The textarea properties clientHeight and clientWidth are in pixels, but appear to be just informational (read-only). The only way I can think of to get the size right is to create the window and the textarea with some starting size that is a guess, and then have a loop where I test clientHeight and clientWidth against the window size and change rows and/or cols accordingly, over and over, until it fits. That seems cheesy. Is there a better way?

I will be specifying my textarea's font-size in CSS, but I like using "pt" for font sizes, and I suspect that the ratio between points, pixels, and textarea rows/cols varies by browser. Even if I used "px" instead, that would only help define the height - the width of a character in the fixed-spaced font of the browser would still be an unknown.
 
While you can specify an initial size for your textarea in row & cols for those with no CSS support, you can simply override these for those who do:

Code:
<textarea rows="5" cols="5" style="width:600px;height:300px;"></textarea>

Hope this helps,
Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
That's exactly what I needed! (Those with no CSS support would find this code useless anyway...)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top