HTML script
<html>
<head></head>
<body>
<form method="POST" action="" enctype="multipart/form-data">
<textarea rows="4" name="text" placeholder="Cambridge is a mental hospital." style="width:50%"></textarea>
<button type="submit" name="submit_form_button" >Submit</button>
<div id="filetext">
</div>
</form>
<script>
var textarea = document.querySelector('textarea');
textarea.addEventListener('keydown', autosize);
function autosize(){
var el = this;
setTimeout(function(){
el.style.cssText = 'height:auto; padding:0';
// for box-sizing other than "content-box" use:
// el.style.cssText = '-moz-box-sizing:content-box';
el.style.cssText = 'height:' + el.scrollHeight + 'px';
},0);
}
</script>
</body>
</html>