Hola
Esto sería un início
Código Javascript
:
Ver original<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
var nuevaFila = {
Evento: function (elemento,nomevento,funcion) {
if (elemento.attachEvent)
{
var f=function(){
funcion.call(elemento,window.event);
}
elemento.attachEvent('on'+nomevento,f);
return true;
}
else
if (elemento.addEventListener)
{
elemento.addEventListener(nomevento,funcion,false);
return true;
}
else
return false;
},
init: function(){
var elem = document.getElementById("txt");
nuevaFila.Evento(elem, 'keyup', nuevaFila.CreaFila);
},
CreaFila: function (ev) {
var num_caracteresIrreales;
var num_caracteresReales;
var keyCode = document.layers ? ev.which : document.all ? event.keyCode : document.getElementById ? ev.keyCode : 0;
var elem = document.getElementById("txt");
num_caracteresIrreales = elem.rows * 26;
num_caracteresReales = elem.value.length;
document.getElementById("irr").innerHTML = num_caracteresIrreales;
document.getElementById("real").innerHTML = num_caracteresReales;
if (keyCode == 8) {
if ((num_caracteresReales < (num_caracteresIrreales-26)) && (elem.rows >=2)) {
elem.rows-= 1;
}
} else if (num_caracteresReales == num_caracteresIrreales) {
elem.rows+= 1;
} else if (keyCode == 13) {
elem.rows+= 1;
num_caracteresIrreales = 26;
num_caracteresReales = 0;
}
}
}
nuevaFila.Evento(window, 'load', nuevaFila.init);
</script>
</head>
<body>
<textarea name="txt" id="txt" cols="30" rows="1" style="overflow:hidden;"></textarea>
Salto linea <span id="irr">0</span> Caracteres <span id="real">0</span>
</body>
</html>
Suerte