Expand textarea to fit a window

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve

    Expand textarea to fit a window

    Hi,

    I'm opening a small window with window.open. I have a textarea there,
    and I want it to expand to fit the window as it's resized. How is this
    possible? Thanks,

    Steve

  • Ivo

    #2
    Re: Expand textarea to fit a window


    "Steve" wrote[color=blue]
    > I'm opening a small window with window.open. I have a textarea there,
    > and I want it to expand to fit the window as it's resized. How is this
    > possible? Thanks,[/color]

    If there is nothing but that textarea in the popup:
    <textarea style="width:10 0%;height:100%" ></textarea>
    (perhaps combined with body{margin:0}. ..)

    On a page with a 100% wide textarea and a small div along the top I use
    this:

    onresize=resize d;
    function resized(){
    scrollTo(0,0);
    var y = window.innerHei ght ? window.innerHei ght :
    document.body.c lientHeight;
    // for better window height, see
    // <URL: http://jibbering.com/faq/#FAQ4_9 >
    var t = document.forms['f'].txt; // the textarea
    t.style.height= Math.max(1,y-txt.offsetTop-1);
    }

    HTH
    Ivo


    Comment

    • Thomas 'PointedEars' Lahn

      #3
      Re: Expand textarea to fit a window

      Ivo wrote:
      [color=blue]
      > If there is nothing but that textarea in the popup:
      > <textarea style="width:10 0%;height:100%" ></textarea>
      > (perhaps combined with body{margin:0}. ..)
      >
      > On a page with a 100% wide textarea and a small div along the top I use
      > this:
      >
      > onresize=resize d;
      > function resized(){
      > scrollTo(0,0);
      > var y = window.innerHei ght ? window.innerHei ght :
      > document.body.c lientHeight;
      > // for better window height, see
      > // <URL: http://jibbering.com/faq/#FAQ4_9 >
      > var t = document.forms['f'].txt; // the textarea
      > t.style.height= Math.max(1,y-txt.offsetTop-1);
      > }[/color]

      With proper use of CSS, that script would be not necessary either.

      BTW: Your "From" header is invalid.


      PointedEars

      Comment

      • Ivo

        #4
        Re: Expand textarea to fit a window


        "Thomas 'PointedEars' Lahn" wrote[color=blue]
        > Ivo wrote:[color=green]
        > > If there is nothing but that textarea in the popup:
        > > <textarea style="width:10 0%;height:100%" ></textarea>
        > > (perhaps combined with body{margin:0}. ..)
        > >
        > > On a page with a 100% wide textarea and a small div along the top I use
        > > this:
        > >
        > > onresize=resize d;
        > > function resized(){
        > > scrollTo(0,0);
        > > var y = window.innerHei ght ? window.innerHei ght :
        > > document.body.c lientHeight;
        > > // for better window height, see
        > > // <URL: http://jibbering.com/faq/#FAQ4_9 >
        > > var t = document.forms['f'].txt; // the textarea
        > > t.style.height= Math.max(1,y-txt.offsetTop-1);
        > > }[/color]
        >
        > With proper use of CSS, that script would be not necessary either.[/color]

        I was kind of hoping someone would say that. How can I stretch the textarea
        to the bottom without knowing the height of the div at the top?
        [color=blue]
        > BTW: Your "From" header is invalid.[/color]

        This computer and email client are used by several individuals, and sender's
        details keep being changed. Is it better now?
        Ivo[color=blue]
        >
        > PointedEars[/color]


        Comment

        • Dr John Stockton

          #5
          Re: Expand textarea to fit a window

          JRS: In article <40b53342@clari on.carno.net.au >, seen in
          news:comp.lang. javascript, Steve <nospam@nopes.? > posted at Thu, 27 May
          2004 10:15:53 :[color=blue]
          >
          >I'm opening a small window with window.open. I have a textarea there,
          >and I want it to expand to fit the window as it's resized. How is this
          >possible?[/color]

          How would one do the opposite? I have a function which creates a button
          which pops up a window containing a single textarea of specified size in
          rows and columns, and it would be nice to have the window of correct
          size to fit it. Under the circumstances, it can be assumed that the
          necessary window size will fit within the screen size.

          What's the best way of determining the number of lines in a function, in
          any browser, given only a reference to the function?

          MJDtoYMD.toStri ng().replace(/[^\r]/g, "").length + 1 // \r\n ??
          MJDtoYMD.toStri ng().split("\r" ).length

          If the FAQ or the Notes have anything on RegExps, a RegExp for newline
          could be worth showing; I fear it may need alternatives.

          --
          © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
          <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
          <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
          <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

          Comment

          Working...