ASP Forum
expandable textarea
stokh | Posted 9:15am 5. August 2002 Server Time |

Does anyone know how to have an expandable textarea.  What I mean is having it start at 1 line and thats all it will show if thats all that is there, but if there is 8 lines in the next record it shows 8 and if 15 lines the next record it shows 15????


Thanks!

Stokh!
mp3cdman | Posted 12:24am 5. August 2002 Server Time |

Here you go girl...

specially written for you...since i've no job so nothing better to do....lol

<html>
<head>
<script>
var maxrows=10;
function doResize() {
var txt=document.all.box1.value;
var arrtxt=txt.split('\n');
if (arrtxt.length>maxrows)
document.all.box1.rows=maxrows;
else
document.all.box1.rows=arrtxt.length;
}
</script>
</head>
<body>
<textarea id="box1" name="box1" rows=1 cols=30 onkeyup="doResize();">Test</textarea>
</body>
</html>

mp3cdman ;-)
mp3cdman | Posted 12:26am 5. August 2002 Server Time |

ooops i never read your last post correctly

just fill the textarea with the correct data then call the doResize() in the onload event of the body tag

mp3cdman
mp3cdman | Posted 12:47am 5. August 2002 Server Time |

in fact if you are pulling the record from a database, say its called "record"

you'll be doing

<textarea name="box1" rows=1 cols=30><%=RS("record")%></textarea>

so just change this to

<%
  intMaxRows=10
  arrRows=Split(RS("record"), vbCrLf)
  intRows=UBound(arrRows)+1
  If intRows>intMaxRows Then intRows=intMaxRows
%>
<textarea name="box1" rows=<%=intRows%> cols=30><%=RS("record")%></textarea>

hey its another solution anyway

mp3cdman ;-)
stokh | Posted 7:39am 7. August 2002 Server Time |

Hey I am going to try this cause they said (the other programmers here) said there wasnt away to do this without JavaScript.  So I will do this and let you know if it works.....

You are truly the MASTER! :)
stokh | Posted 8:59am 7. August 2002 Server Time |

Ok I assume that box1 is the name of the field so I would have to write the script to match every field that I want this to occur...man nothing can never be easy can it! :(

stokh | Posted 9:23am 7. August 2002 Server Time |

can you do it with a text box as well?
mp3cdman | Posted 10:18am 7. August 2002 Server Time |

hey stokh

i'm sure you can do it for textboxes to in fact gimme a half an hour and i'll try to write one which will work for whatever you use it on...

mp3cdman

the asp version will only set the size of the textare based on what comes from the database... it wont resize on the webpage dynamically unless you use Javascript or VBscript client side...
stokh | Posted 10:28am 7. August 2002 Server Time |

Yeah I got that, so then I need to use this
var maxrows=10;
function doResize(){
var txt=document.all.custLocation.value;var arrtxt=txt.split('\n');
if (arrtxt.length>maxrows)
document.all.custLocation.rows=maxrows;
else
document.all.custLocation.rows=arrtxt.length;

for each field that I need it to grow on?  Correct?

half hour is fine i will be here for another hour and then time to go home and no working at home today getting ready to go on vacation and kids have football camp starting this afternoon:)

I get 4 whole days in Santa Monica on the Ocean.....YIPPY
mp3cdman | Posted 10:34am 7. August 2002 Server Time |

hi again

try this

<html>
<head>
<script>
var maxrows=10;

function doResize(box) {
var txt=box.value;
var arrtxt=txt.split('\n');
if (arrtxt.length>box.maxrows)
box.rows=box.maxrows;
else
box.rows=arrtxt.length;
}
</script>
</head>
<body>
<textarea id="box1" name="box1" rows=1 cols=30 onkeyup="doResize(this);" onkeydown="doResize(this);" maxrows=5>Test</textarea>
<textarea id="box2" name="box2" rows=1 cols=30 onkeyup="doResize(this);" onkeydown="doResize(this);" maxrows=10>Test</textarea><br>
<textarea id="box3" name="box3" rows=1 cols=30 onkeyup="doResize(this);" onkeydown="doResize(this);" maxrows=15>Test</textarea>
<textarea id="box4" name="box4" rows=1 cols=30 onkeyup="doResize(this);" onkeydown="doResize(this);" maxrows=20>Test</textarea>
</body>
</html>

it allows you to put maxrows=x in each textare to determine how big the box can be...

mp3cdman
mp3cdman | Posted 10:35am 7. August 2002 Server Time |

well you have a good vacation and i hope this helps you out

mp3cdman
stokh | Posted 10:39am 7. August 2002 Server Time |

MP the other one doesnt do what I want it to do on one of the pages,  it is the page that they input the data into and the field needs to grow as they type so if they go from typing 1 line to 8 lines then 8 lines is showing on that form as they are typing does that make sense.

testingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtesting

so as each new line comes it should be exposed to the page at the same time, so the field is growing based on what they are adding to it at the time they are adding it...

CLear?

ANd you are the best  no vacation yet got another day of all work....
mp3cdman | Posted 10:42am 7. August 2002 Server Time |

oh right you mean it dont work if the line wraps onto a new line because it only counts newline chars and not line wraps..

that should be just a case of checking each line for more than x number of characters....

gimmme a min

mp3cdman
stokh | Posted 10:45am 7. August 2002 Server Time |

ok you broke the page MP...LOL  ok hanging :)
mp3cdman | Posted 10:55am 7. August 2002 Server Time |

is this more what you want

<html>
<head>
<script>
var maxrows=10;

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>
</head>
<body>
<textarea id="box1" name="box1" rows=1 cols=30 onkeyup="doResize(this);" onkeydown="doResize(this);" maxrows=5>Test</textarea>
<textarea id="box2" name="box2" rows=1 cols=30 onkeyup="doResize(this);" onkeydown="doResize(this);" maxrows=10>Test</textarea><br>
<textarea id="box3" name="box3" rows=1 cols=30 onkeyup="doResize(this);" onkeydown="doResize(this);" maxrows=15>Test</textarea>
<textarea id="box4" name="box4" rows=1 cols=30 onkeyup="doResize(this);" onkeydown="doResize(this);" maxrows=20>Test</textarea>
</body>
</html>

it will also count lines which wrap!!

mp3cdman
mp3cdman | Posted 10:56am 7. August 2002 Server Time |

oh and stokh it was your testingtestingtesting.... etc that broke the page.....silly girl......lol

mp3cdman ;-)
mp3cdman | Posted 10:59am 7. August 2002 Server Time |

oh and it seems that if you dont put a maxrows attribute in the box then it will happily expand forever

mp3cdman ;-)

nice touch...lol
stokh | Posted 11:03am 7. August 2002 Server Time |

No job yet?  That is such a bummer!  I tell you you got to move to the states....Why not do consulting?  and I am trying this one and will let ya know in a second....

I broke the page...hmmm how the heck did I do that  LOL
stokh | Posted 11:07am 7. August 2002 Server Time |

OH YOU ARE TRULY MY HERO!  :)  Why dont you come on over here and just be my personal teacher....LOL  hmm what will we all do when your to big for this forum we will have truly lost the Great!  :)

Ok so will this code work for a text box too?  I only used it on the textarea

Thank you sunshine! :)

Stokh
stokh | Posted 11:17am 7. August 2002 Server Time |

well does it work for text boxes too MP????

Otherwise i will check with ya in the morning remember i am here at 5am my time so not sure what time that is there but some where around 10 or 11 I think...

Thanks a million! :)

Stokh
stokh | Posted 11:19am 7. August 2002 Server Time |

and one other thing, can I make the return read only?
pacoonejr | Posted 2:07pm 7. August 2002 Server Time |

u 2 broke the forum! have fun at the coast kid-o
stokh | Posted 6:14am 8. August 2002 Server Time |

Nope it wasnt me!  It was MP I am sure of it! :)  LOL

Yeah I will try to have fun!

Thanks!

Stokh
stokh | Posted 6:51am 21. October 2002 Server Time |

What if all the fields that I want to use this on have different names as mine do?  

There are 4 textarea fields all named differently so calling them "box" isnt an option

any ideas?

Stokh
ranaluk | Posted 6:34am 2. November 2009 Server Time |

Hi all,

I am trying for expandable textArea , here I am getting the values from Db , The example that u hav posted here is not working in my page , can anyone help me ? .

Thanks in advance.


Reply to Post expandable textarea



Back to Forum Page