Autosizing textbox

Doe sanyone know how I can make a multiline text box that grows vertically
as more text is entered (basically no scroll bars)?
Tirrell Cotton [ Mo, 07 April 2008 21:52 ] [ ID #1937016 ]

Re: Autosizing textbox

I threw this together haphazardly for IE 6. I didn't test it on other
browsers, but you could use it as a starting point if you don't mind
using javascript.

The script.
=A0 =A0 <script type=3D"text/javascript">
//this is the number I got when you only have one line in the
textArea
=A0 =A0 var height =3D 20;
=A0 =A0 function getHeight(){
var txtArea =3D document.getElementById("textArea");

//debugging purposes only
document.getElementById("txt").value =3D
txtArea.scrollHeight;

//if the scrollHeight is bigger than what we started with,
then add to the size of the box
if (txtArea.scrollHeight > height) {
txtArea.rows=3DtxtArea.rows + 1;
height =3D txtArea.scrollHeight;
}
}
=A0 =A0 </script>

And here are the form elements. The textbox was only for debugging
purposes.
=A0 <input type=3D"text" id=3D"txt" />
=A0 =A0 <textarea id=3D"textArea" rows=3D"2" cols=3D"45"
onkeydown=3D"getHeight();"></textarea>

This assumes that you're starting with an empty textarea, so you'll
have to add to it a bit if the textArea is full. Hope it helped!
PopeDarren [ Di, 08 April 2008 00:39 ] [ ID #1937704 ]

Re: Autosizing textbox

That worked ( after a little tweaking for server side controls). I also
managed to get the textbox to shrink if text is removed. Thanks again.


"Tirrell Cotton" <tcotton73 [at] sbcglobal.net> wrote in message
news:958C1DA3-65B4-468F-AA6F-08ADF66371A0 [at] microsoft.com...
> Doe sanyone know how I can make a multiline text box that grows vertically
> as more text is entered (basically no scroll bars)?
Tirrell Cotton [ Mi, 09 April 2008 22:28 ] [ ID #1938687 ]
Microsoft » microsoft.public.dotnet.framework.aspnet » Autosizing textbox

Vorheriges Thema: Change css element with C#
Nächstes Thema: Baume and Mercier Capeland S Mens Watch 8319