Ver Mensaje Individual
  #3 (permalink)  
Antiguo 16/11/2002, 14:01
Avatar de Carlitos
Carlitos
Usuario no validado
 
Fecha de Ingreso: mayo-2001
Ubicación: Zaragoza
Mensajes: 1.304
Antigüedad: 23 años
Puntos: 25
Para limitar el campo copete:

<input type="text" name="copete" size="40" onKeyDown="limite(this,200)" onKeyUp="limite(this,200)">
El 200 lo cambias por el límite que le quieras poner.

Pero esto te hará funcionar mal el contador del textarea. Para solucionarlo, tendrías que repetir la función. O quitar el contador si no lo usas.

Ejemplo 1. Repitiendo la funcion:

<html>
<head>
<script language="JavaScript">
// Limita los caracteres a introducir en un TextArea y cuenta los que quedan para llegar al final. En este caso, son 200. Para modificar el tamaño, solo hay que cambiar este valor en 'limite(this,200)' y en 'value=200' por el deseado.

function limite(que,cuanto)
{
var v=que.value
if(v.length>cuanto) que.value=v.substring(0,cuanto)
else document.reduce.cont.value=cuanto-v.length
}
function limite2(que,cuanto)
{
var v=que.value
if(v.length>cuanto) que.value=v.substring(0,cuanto)
else document.reduce2.cont2.value=cuanto-v.length
}

</script>
</head>
<body>

<p><br>
<form method="POST" action="agrega_noticia.asp" name=reduce2">
<p>Categoria:</p>
<p><input type="text" name="Categoria" size="40"> </p>
<p>Titulo:<br>
<input type="text" name="titulo" size="40">
</p>
<p>Copete:<br>
<input type="text" name="copete" size="40" onKeyDown="limite2(this,200)" onKeyUp="limite2(this,200)"</p>
<input name="cont2" type="text" size="3" value="200" readonly>
</p>
</form>
<form name="reduce">
<textarea onKeyDown="limite(this,200)" onKeyUp="limite(this,200)" name="registro" rows=15 cols=45 ></textarea>
<input name="cont" type="text" size="3" value="200" readonly>
</form>
</body>
</head>
</html>


Ejemplo 2. Quitando el contador.

<html>
<head>
<script language="JavaScript">
// Limita los caracteres a introducir en un TextArea y cuenta los que quedan para llegar al final. En este caso, son 200. Para modificar el tamaño, solo hay que cambiar este valor en 'limite(this,200)' y en 'value=200' por el deseado.

function limite(que,cuanto)
{
var v=que.value
if(v.length>cuanto) que.value=v.substring(0,cuanto)
}
</script>
</head>
<body>

<p><br>
<form method="POST" action="agrega_noticia.asp">
<p>Categoria:</p>
<p><input type="text" name="Categoria" size="40"> </p>
<p>Titulo:<br>
<input type="text" name="titulo" size="40">
</p>
<p>Copete:<br>
<input type="text" name="copete" size="40" onKeyDown="limite(this,200)" onKeyUp="limite(this,200)"></p>
</form>
<form name="reduce">
<textarea onKeyDown="limite(this,200)" onKeyUp="limite(this,200)" name="registro" rows=15 cols=45 ></textarea>
</form>
</body>
</head>
</html>

Última edición por Carlitos; 16/11/2002 a las 14:07