function grow() {Became:
// Opera isn't just broken. It's really twisted.
if (this.scrollHeight > this.clientHeight && !window.opera)
this.rows += 1;
}
function grow(control, minimumRows) {Two parameters, one submitting the control itself (this) and one giving the minimum amount of rows to know how far to shrink. This way it grows until it fits, for example after a paste more than 1 line might have been added at once. I also add the grow() call to 'onfocus' and 'onblur' to be even more sure the size is correct. And because the Textarea is first reset to it's initial size by the minimumRows parameter it will also decrease.
control.rows = minimumRows;
if(control.scrollHeight > control.clientHeight)
{
// Grow till it fits
while(control.scrollHeight > control.clientHeight)
{
control.rows += 1;
}
}
}
Decreasing / shrinking is dirty
Until now I haven't found a pretty way to decrease the Textarea as I can't find any way to measure this.
Have fun using this and post any comments to make this even better!