Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to autosize a textarea with the window?

Posted on 2005-03-01
2
Medium Priority
?
1,040 Views
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!
0
Comment
Question by:justJason
2 Comments
 
LVL 31

Assisted Solution

by:GwynforWeb
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
0
 
LVL 16

Accepted Solution

by:
ellandrd earned 480 total points
ID: 13431129
<HTML>
<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;
  }

</script>

<BODY>
<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>
</table></form></BODY></HTML>
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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

578 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