wjw Posted June 15, 2006 Share Posted June 15, 2006 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 More sharing options...
Little Goat Posted June 15, 2006 Share Posted June 15, 2006 onkeypress="this.size=this.value.length+1"add that attribute. (I have not tested it.) Link to comment Share on other sites More sharing options...
scott100 Posted June 15, 2006 Share Posted June 15, 2006 onkeypress="this.size=this.value.length+1"add that attribute. (I have not tested it.)<{POST_SNAPBACK}> 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 More sharing options...
Chocolate570 Posted June 15, 2006 Share Posted June 15, 2006 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 More sharing options...
scott100 Posted June 15, 2006 Share Posted June 15, 2006 Scott, that's a great idea, but unfortunatley, when you press backspace, it grows longer and longer. That probably wont help <{POST_SNAPBACK}> 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 More sharing options...
wjw Posted June 15, 2006 Author Share Posted June 15, 2006 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 <{POST_SNAPBACK}> 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 More sharing options...
scott100 Posted June 15, 2006 Share Posted June 15, 2006 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now