How to autosize a textarea with the window?

Posted on 2005-03-01
Medium Priority
Last Modified: 2008-01-09
Let's say you have a textarea in a HTML form.
Now you reduce the size of the window.
I need to autosize the textarea as well, otherwise I must scroll down to find the textarea.

How do you reduce the size of the textarea with the window?

I can't seem to find an answer to this.
Thanks in advance for any help!
Question by:justJason
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 31

Assisted Solution

GwynforWeb earned 120 total points
ID: 13430374
A piece of advice is not to try to resize evreything for window, you are asking for trouble and mostly people do not like it
LVL 16

Accepted Solution

ellandrd earned 480 total points
ID: 13431129
<script language=JavaScript>
  function ResizeTextArea(txtBox)
        nCols = txtBox.cols;
        sVal = txtBox.value;
        nVal = sVal.length;
        nRowCnt = 1;
        for (i=0;i<nVal;i++)
        {   if (sVal.charAt(i).charCodeAt(0) == 13) { nRowCnt +=1; } }  
        if (nRowCnt < (nVal / nCols)) { nRowCnt = 1 + (nVal / nCols); }
        txtBox.rows = nRowCnt;


<form   name=frmSubmit method=post   >
<table border=0 cellspacing=1 cellpadding=1 width='70%' align=center>
<tr><td align=left><textarea  name=txtTest cols=50 rows=1 style='overflow:hidden'> </textarea></td></tr>
<tr><td align=left><a href=# onclick="ResizeTextArea(document.frmSubmit.txtTest);" >Resize</a></td></tr>

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question