Navigation Menu

Site Contents
What's New?


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

Partner With Us
Ram Memory
Promote Your Website
Televisions
Imprinted Promotions
Promotional Golf
Dental Insurance
Online Universities
Promotional Products
PDA Phones & Cases
Imprinted Gifts
Promos and Premiums
GPS
Laptops
Logo Design

Internet.com

IT
Developer
Internet News
Small Business
Personal Technology
International

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]

    
   
       
[optional field]
 
[optional field]

   

Comments feed Comment Feed RSS 2.0

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.