Hi I have a function to increase the No. of rows of a textarea when the user types on it, so it works fine. But when the form brings the text into the textarea as the user is not typing in, it does not increase the number of rows, but it shows only the number of rows defined at the beginning (rows="1"), as I need it to be the smallest number of rows.
I don't know what Javascript (no JQuery) function to apply to the textarea so it would expand the No. of rows, when the user types, and when the form bring up a multi line text to the textarea, so it will always uses the minimum amount of rows.
Any help would be appreciated.
Please fell free to change function I have completely.
eg.
<script type="text/javascript">
function changeTextAreaLength(e){
var txtLength = e.value.length;
var numRows = 0 ;
var arrNewLines = e.value.split("\n");
for(var i=0; i<=arrNewLines.length-1; i++){
numRows++;
if(arrNewLines[i].length > e.cols-5) {
numRows += Math.floor(arrNewLines[i].length/e.cols)
}
}
if(numRows < 1) {
e.cols = (txtLength % e.cols) + 1 >= e.cols ? ((txtLength % e.cols) + 1) : e.cols ;
}else{
e.cols = e.cols ;
e.rows = numRows;
}
}
</script>
<textarea id="textarea1" rows="1" onkeyup="javascript:changeTextAreaLength(this);" />