TU FORO 404
PortalIndiceGaleríaAfiliadosFAQBuscar RegistrarseConectarseRegistrarse
   
  Tu Portal de Ayudas 404
  Textarea con contador de Caracters o Limitador de Caracteres
 
Cuenta el numero de carcteres, que se escriben en la textarea.

Código:
<script>
function cuenta(){
document.forms[0].caracteres.value=document.forms[0].texto.value.length
}
</script>
<form action="#" method="post">
<table>
<tr>
<td>Texto:</td>
<td><textarea cols="40" rows="5" name="texto" onKeyDown="cuenta()" onKeyUp="cuenta()"></textarea></td>
</tr>
<tr>
<td>Caracteres:</td>
<td><input type="text" name=caracteres size=4></td>
</tr>
</table>
</form>

Aqui otra version, que limita el numero de caracteres, y si intentas te pasas se borran solos.
Código:
<html>
<head>
<script language="Javascript" type="text/javascript">

function contador (campo, cuentacampo, limite) {
if (campo.value.length > limite) campo.value = campo.value.substring(0, limite);
else cuentacampo.value = limite - campo.value.length;
}

</script>
</head>
<body>
<center>
<form name="form1">
Maximo 125 Caracteres
<textarea name="mensaje" wrap=physical cols="28" rows="4" onKeyDown="contador(this.form.mensaje,this.form.remLen,125);" onKeyUp="contador(this.form.mensaje,this.form.remLen,125);"></textarea>
<input type="text" name="remLen" size="3" maxlength="3" value="125" readonly>Quedan
</form>
</center>
</body>
</htm>

_____
 
  Derechos reservados a TuForo404.com  
 
Este sitio web fue creado de forma gratuita con PaginaWebGratis.es. ¿Quieres también tu sitio web propio?
Registrarse gratis