This function will set the height of the element (textarea, in your case) to the browser's default height. If that causes a scrollbar to appear, the height will be switched to the actually needed height.
function autoHeight(element){ element.style.height='auto'; element.style.height=element.scrollHeight+'px';}
If you don't like the browser's default height, you can change that to some other default value of your own, of course.