views:

121

answers:

3

In my ASP.NET page I have a text box which shows data which is bind to an (JavaScript) object variable. I want that textbox to resize everytime, the JavaScript object, e.g. result.title will change everytime.

Important: I want to fit the textbox exactly to the text length inside.

A: 

You could use onChange:

<textarea onChange="resize(this)"></textarea>

<script>
function resize(el) {
    el.cols = el.value.length;
}
</scrip>

Btw are you using Ajax?

watain
+1  A: 

Here is a great tutorial that teaches you how to make a jQuery plugin to do exactly what your talking about.

UmYeah
A: 

Here's a jQuery plug-in: http://www.unwrongest.com/projects/elastic/

Nissan Fan