Jump to content

Textarea autogrow


wjw

Recommended Posts

Does anyone know how to make a textarea grow vertically as the user enters text? IE6 does this if you set Display: visible. I know it's an IE bug, but it's the behavior I want and can't get other browsers to do it. Hopefully there is some CSS attribute that will do this.Any help is greatly appreciated!Jason

Link to comment
Share on other sites

onkeypress="this.size=this.value.length+1"add that attribute. (I have not tested it.)

It's a bit more complicated i think
<head><script>function resize(){x=document.getElementById('txt').style.height;x=eval( x.slice(0,x.length-2) );x=x+10;document.getElementById('txt').style.height=x;}</script></head><body><textarea style="height:100px;" id="txt" onkeypress="resize();"></textarea><body>

Link to comment
Share on other sites

Scott, that's a great idea, but unfortunatley, when you press backspace, it grows longer and longer. That probably wont help :)

Link to comment
Share on other sites

Scott, that's a great idea, but unfortunatley, when you press backspace, it grows longer and longer. That probably wont help :)

Thats true :) You could always merge it somehow with this script that detects the length of the textarea and recognises backspace: http://www.dynamicdrive.com/dynamicindex16/limitinput.htm :)
Link to comment
Share on other sites

Thats true  :) You could always merge it somehow with this script that detects the length of the textarea and recognises backspace: http://www.dynamicdrive.com/dynamicindex16/limitinput.htm  :)

Well I was hoping for a simple combination of CSS attributes that would do the trick but it doesn't look like that's going to happen. I see the potential with scott100's suggestion and will give that a shot early next week. If I get it to work I'll post it.Thanks for the help!
Link to comment
Share on other sites

I see the potential with scott100's suggestion and will give that a shot early next week.  If I get it to work I'll post it.
Actually it might not be as hard as i thought to stop it "growing" when delete is pressed.when a key is pressed call the functionDetect which key was pressedif it was the delete key - if(charCode==8) - then delete the length - x=x-10;else it wasn't the delete key so let the textarea grow - x=x+10;That should do it :)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...