<script type="text/javascript">
window.onload = function(){
document.getElementsByClassName("element").onkeyup = function(){
var getText = this.value;
var getRegs = getText.match(/^.*(\r\n|\n|$)/gim);
var setText = false;
for(var i = 0; i < getRegs.length; i++){
getText = getRegs[i].replace(/\r|\n/g, "");
setText += getText.length ? Math.ceil(getText.length / 50) : 1;
}
this.rows = setText;
};
var elements = document.getElementsByClassName("element");
for (var i = 0; i < elements.length; i++) {
elements[i].onkeyup = function(){
var getText = this.value;
var getRegs = getText.match(/^.*(\r\n|\n|$)/gim);
var setText = false;
for(var i = 0; i < getRegs.length; i++){
getText = getRegs[i].replace(/\r|\n/g, "");
setText += getText.length ? Math.ceil(getText.length / 50) : 1;
}
this.rows = setText;
};
};
};
</script>
Я очень далёк от истины? )
<textarea rows="2" cols="50" class="element" style="overflow: hidden; min-height: 40px"></textarea>
<textarea rows="2" cols="50" class="element" style="overflow: hidden; min-height: 40px"></textarea>