How do I dynamically size a <HTML:TEXTAREA>????

Discussion in 'HTML' started by Anders S. Clausen, Nov 22, 2003.

  1. Hi

    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???

    Cheers.

    Anders
     
    Anders S. Clausen, Nov 22, 2003
    #1
    1. Advertising

  2. Anders S. Clausen wrote:

    > he 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 ....


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

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me - http://www.goddamn.co.uk/tobyink/?page=132
     
    Toby A Inkster, Nov 22, 2003
    #2
    1. Advertising

  3. Anders S. Clausen wrote:

    > 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.


    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.

    --
    Bertilo Wennergren <> <http://www.bertilow.com>
     
    Bertilo Wennergren, Nov 22, 2003
    #3
  4. hi,
    simply access the style-elements you usually
    set statically in your css.

    /* resize specific textfield */
    function resizeElement(x,y)
    {
    document.formName.elementName.style.height = y;
    document.formName.elementName.style.width = 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.

    yours
    matthias
     
    Matthias H. Risse, Nov 23, 2003
    #4
  5. Toby A Inkster <> wrote:

    >> he 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 ....

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


    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, http://www.cs.tut.fi/~jkorpela/
    Pages about Web authoring: http://www.cs.tut.fi/~jkorpela/www.html
     
    Jukka K. Korpela, Nov 24, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Anders S. Clausen
    Replies:
    5
    Views:
    937
    Jukka K. Korpela
    Nov 24, 2003
  2. Augustus
    Replies:
    1
    Views:
    362
    Ken Schaefer
    Sep 10, 2003
  3. Textarea Inside of a textarea

    , Feb 4, 2006, in forum: ASP General
    Replies:
    6
    Views:
    337
    Anthony Jones
    Feb 5, 2006
  4. Anders S. Clausen

    How do I dynamically size a <HTML:TEXTAREA>????

    Anders S. Clausen, Nov 22, 2003, in forum: Javascript
    Replies:
    7
    Views:
    156
    Jukka K. Korpela
    Nov 24, 2003
  5. Replies:
    1
    Views:
    320
    Bart Van der Donck
    Jul 4, 2007
Loading...

Share This Page