Navigation Menu
Alphabetical Listing
Site Contents

Site FAQ
About JSS
JavaScript Forum
JavaScript Tutorial
Friends of JSS

Link to Us
JavaScript Help
Contribute a script
Technology Jobs

Become a Partner

Internet.commerce

Be a Commerce Partner














Internet.com

IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

Developer Channel

FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

Great Sites

DocJavaScript.com
dhtml.com
The Freebie Directory
TheFreeSite.com

Browse Doc JS's Tips!


Hiermenus Central


Promotions

Free Announcements


Social Bookmark

General

You no longer need to provide large textareas in your forms. This script will resize textarea boxes to fit the text in them.


Click here to try it out!

Notes

To make a textarea none-resizeable, just add the following to the textarea element: onkeyup="";, e.g.,
<textarea cols="40" rows="2" name="reason3" onkeyup="">Add more text to see it expand!</textarea>

Source Code

Paste this source code into the designated areas.

External file

Paste this code into an external JavaScript file named: textArea Sizer.js


Head

Paste this code into the HEAD section of your HTML document.


Body

Paste this code into the BODY section of your HTML document


User Comments

Add a comment, suggestion, or correction
[For questions about usage, consult the Notes tab above or visit the JavaScript forum. Do not include more than two (2) lines of code in your comments. If you have suggestions or corrections, you can submit them to us.]

    
   
       
[optional]
 
[optional]

   

Comments feed Comment Feed RSS 2.0

8. From: Paul
Initial Size of Texzt Box Too Large
10/11/2008 22:52:29

I have installed this javascript into my form I am creating and notice the default text size box is approximately 3 lines tall.

How can I change this so it is initially only one line tall?

Thanks,

Paul

9. From: Lee (Admin)
11/06/2008 11:40:49

Change the textarea input setting:

<textarea cols="40" rows="1" name="reason">Add more text to see it expand!</textarea>

Otherwise, it is probably an error in the CSS settings.

7. From: Gordon Murray
Suggestion
09/24/2008 22:56:36

How about adding a couple more functions like a calculator that processes equations inside the text box and/or has running word/character count and/or countdown for n word and/or n character limits?

6. From: NicMason.com
Thank you!
07/24/2008 01:51:21

Great piece of code! Just what I've been looking for. Cheers! NicMason.com - Yarraville.com.au

2. From: EZboy
05/04/2007 15:37:00

I modified the code a bit:

function cleanForm() {

for(var no=0;no<document.forms.length;no++){
var the_form = document.forms[no];
for ( var x in the_form ) {
if ( ! the_form[x] ) continue;
if( typeof the_form[x].rows != "number" ) continue;

if(!the_form[x].onkeyup){ the_form[x].onkeyup=function() {this.rows = countLines(this.value,this.cols) +1;};the_form[x].rows = countLines(the_form[x].value,the_form[x].cols) +1; }
}
}
}

Using this function instead of a provided one will apply resize property to all text areas on a page and uses onkeyup even, doesn't load the page a lot. If you dont want the resize property applied to some textarea, just apply a dummy onkeyup function to it


4. From: Douglas McKibbin
Where do I put the .js file
03/30/2008 18:50:35

Using a MacOSX and iWeb, where do I place the .js file?
Thanks for the code,
Doug

5. From: Lee (Admin)
06/26/2008 11:33:22

In order to better help you, you'll need to post your question over on the forums.

3. From: Lee (Admin)
08/07/2007 14:27:34

Sweet! I modified the code and gave you credit. Thanks!

1. From: Wiz Feinberg
03/16/2007 14:31:17

This expandable form only expands the text vertically in Internet Explorer browsers. Using Firefox, my primary browser, it only expands vertically once, then continues to expand horizontally, on the second line, creating a horizontal scrollbar. While this happens, the box gets taller, vertically, but the text does not wrap to fill the new vertical space.

It needs work to be compliant in non-IE browsers.



Do you write JavaScripts?
If you do, why not submit them to us?
We'll give you credit and a link back to your Web site.