Mike Mehraban

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromMike Mehraban
ToMe
SubjectRe-sizing Textarea does not work in Mozilla
Date7 July 2005 20:11
Hello Tarquin,
I have a function that resizes a textarea at load time of my HTML page to fit
the browser screen.  It works fine with IE 6.0.  However, when I try it with
Mozilla or FireFox, it does not fit properly and causes a vertical scrollbar to
appear.  Can you please tell me why the function does not work for Mozilla and
how I can fix it.  The code for resize function is:

function resize(){
var obj = document.form1.<%= WsoConst.PARM_DATA %>;
var rht = obj.clientHeight / obj.rows;
var otherHt = document.getElementById("thd").offsetHeight+document.getElementById("tin").offsetHeight +30;
var rws =((document.body.clientHeight -otherHt)/rht)-1; obj.rows = (rws > 1)?rws:1;
}


Regards, Mike.
FromMe
ToMike Mehraban
SubjectRe: Re-sizing Textarea does not work in Mozilla
Date8 July 2005 12:42
Mike,

> It works fine with IE 6.0.  However,
> when I try it with Mozilla or FireFox, it does not fit properly and
> causes a vertical scrollbar to appear.

What about when you try it in Opera? I trust you are testing in that as well
(since that is the browser I use myself, and it is available for free, cross
platform). There are also Safari, iCab, OmniWeb, Konqueror, and many others.
If you have a Mac, please also test Safari/OmniWeb, icab, and IE Mac. If you
have linux, please also test Konqueror. Whatever platform you use, please
also test Opera. Let me know which ones fail to do what you wanted.

> Can you please tell me why
> the function does not work for Mozilla and how I can fix it.

Not without the rest of the code, no. Since I have no idea what 'thd' or
'tin' are, or how many rows exist in the textarea (default is -1 if you do
not specify it). Please send me the address of the page so that I can see it
for myself online.

> var rht = obj.clientHeight / obj.rows;

I recommend using offsetHeight, since clientHeight can produce some very
strange results in different browsers. (offsetHeight also takes the
scrollbars into account).

> ((document.body.clientHeight -otherHt)/rht)-1;

Do not just use document.body.clientHeight - that does not work properly
cross browser, and produces different results in IE depending on whether you
are using strict or quirks mode rendering. See my window size page for more
details:
http://www.howtocreate.co.uk/tutorials/javascript/browserwindow


Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
FromMike Mehraban
ToMe
SubjectRe: Re-sizing Textarea does not work in Mozilla
Date8 July 2005 19:08
AttachmentJSP source file (why can't people ever send me a URL?!)
Hi,
 
Thanks for your quick response. 
I downloaded Opera, but my application is not running under Opera for some
reason.  I have to figure that out.  
I have attached to this email the complete jsp file that I am using.
I also tried with obj.offsetHeight instead of obj.clientHeight and
window.innerHeight instead of document.body.clientHeight with no luck.

Regards, Mike.
FromMe
ToMike Mehraban
SubjectRe: Re-sizing Textarea does not work in Mozilla
Date9 July 2005 16:16
Mike,

ok, I took a look at the attached JSP source code. Note that I do not know
JSP well enough to work out what you are doing here. It would be a lot more
useful if I could see the actual outputted web page, so I could also work
out how your external script files or stylesheets might affect it.

Anyway, the problem seems to be that you are trying to get the dimensions of
spans. Spans are inline elements, and their sizes may change for various
reasons, and browsers often have problems working out the sizes of them. I
recommend using block level elements (such as DIVs or spans with their
display set to block.

If that does not help, please send me the address of the page while it is
online so I can see it fail for real.
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.