How do I dynamically size a ????

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I have a jsp with a couple of <HTML:TEXTAREA> where I would like to
dynamically size the textarea depending on the length of a String entered on
a different jsp. The two new textareas are to display the full text (and no
scroll bars), and I was wondering what I set the row and cols to ....
keeping in mind that I have the length of the text I want to display.
Any ideas???



Re: How do I dynamically size a ????

Anders S. Clausen wrote:

Quoted text here. Click to load it

Wouldn't <pre> make more sense than <textarea>?

Toby A Inkster BSc (Hons) ARCS
Contact Me -

Re: How do I dynamically size a ????

Quoted text here. Click to load it

Partly. It would avoid misleading the user into thinking that there is a
text input area, which is what textarea is for.

But there's usually no reason to use clumsy preformatted text in HTML at
all. Why would anyone write plain text formatted to specific line length
when you can do things the HTML way, with paragraph markup and all that?

As usual, posting a description of a problem, rather than a misguided
attempt to approach an unspecified problem, would probably lead to a good
solution. Especially if pointless crossposting is omitted.

Followups trimmed.

Yucca, /
Pages about Web authoring:

Re: How do I dynamically size a ????

Anders S. Clausen wrote:

Quoted text here. Click to load it

You don't really have the lenght of the text, if you mean the width and
height it will take to display it, since you can't know what font and
font size will be used. If you're lucky, a fixed width font will be
used, which makes it easier, be you can't count on that.


Re: How do I dynamically size a ????

simply access the style-elements you usually
set statically in your css.

/* resize specific textfield */
function resizeElement(x,y)
{ = y; = x;

this would be more elegant / flexible, but is untested:

  * @param     id    id of to be modified element
  * @param     x    new width in pixel
  * @param     y    new height in pixel
function resizeElement(id,x,y)
    var a = 30;
    var b = 30;

    document.getElementById(id).style.height = y-a;
    document.getElementById(id).style.width = x-b;

you could e.g. call this in <body> tag on events onLoad and/or
onResize, depending on your needs. remember to give your textarea
an id="foo" attriute for this one.


Site Timeline