Go Back   SitePoint Forums > Forum Index > Program Your Site > JavaScript
Newsletter FAQ Members List Calendar Mark Forums Read

New to SitePoint Forums? Register here for free!

SitePoint Sponsor
 
Reply
 
Thread Tools Display Modes
Old Nov 8, 2009, 12:25   #1
jmansa
SitePoint Evangelist
 
Join Date: Dec 2005
Posts: 595
Textarea collapses?!?

I have this expandable textarea which works fine except... Whe a user starts typing it collapses inti 1 row and from there expands as it should even though I have set the rows to 4? How do I get passed this?

Code:
<script>
var maxrows=50;

function doResize(box) {
var txt=box.value;
var cols=box.cols;
var arrtxt=txt.split('\n');
var rows=arrtxt.length;
for (i=0;i<arrtxt.length;i++)
  rows+=parseInt(arrtxt[i].length/cols);
if (rows>box.maxrows)
box.rows=box.maxrows;
else
box.rows=rows;
}
</script>

<textarea class="expandtextarea2" id="box1" name="box1" rows=4 cols="56" onkeyup="doResize(this)" onkeydown="doResize(this)">
Thanks in advance...
jmansa is offline   Reply With Quote
Old Nov 8, 2009, 12:49   #2
RLM2008
SitePoint Enthusiast
 
RLM2008's Avatar
 
Join Date: Nov 2008
Location: Thailand
Posts: 74
This seems to do the trick

change

HTML Code:
var rows=arrtxt.length;
to

HTML Code:
var rows=(arrtxt.length<4)?4:arrtxt.length;
RLM
RLM2008 is offline   Reply With Quote
Old Nov 8, 2009, 14:28   #3
jmansa
SitePoint Evangelist
 
Join Date: Dec 2005
Posts: 595
Thanks... Did the job :-)
jmansa is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread | Next Thread »

Thread Tools
Display Modes

 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Sponsored Links
 
Forum Jump


All times are GMT -7. The time now is 04:55.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright 1998-2009, SitePoint Pty Ltd. All Rights Reserved