Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change textarea height as user types

Status
Not open for further replies.

vlitim

Programmer
Sep 2, 2000
393
GB
Is it possible to change the height of a textarea as the user types. IE if at first you can type 3 lines into it when they start typing the forth line it will size the textarea accordingly.

Cheers
tim
 
Here's one I wrote for another question on this site:

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "[URL unfurl="true"]http://www.w3.org/TR/html4/strict.dtd">[/URL]

<html>
<head>
<title>auto-expand textarea</title>

<script language="javascript" type="text/javascript">
<!--

function expandTA() {
    var ta = document.forms['the_form'].elements['ta'];
    var l = ta.value.split('\n').length;
    ta.rows = l;
}

onload = expandTA;

-->
</script>

</head>

<body>

<form name="the_form">
  <textarea name="ta" rows="5" cols="50" onkeyup="expandTA();" wrap="off">Here is sample text.</textarea>
</form>

</body>

</html>

*cLFlaVA
----------------------------
[tt]clean slate...[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top