Ver Mensaje Individual
  #2 (permalink)  
Antiguo 27/08/2007, 02:18
Avatar de caricatos
caricatos
Moderador
 
Fecha de Ingreso: abril-2002
Ubicación: Torremolinos (Málaga)
Mensajes: 19.607
Antigüedad: 22 años, 1 mes
Puntos: 1284
Re: Controlar número de checkbox marcados

Hola:

Tal vez te sirva algo así:

Código:
<html>
<head>
<script>
var maxi = 3;
function registra(c) {
cuenta = 0;
for (i = 0, f = c.form, n = c.name, total = f[n].length; i < total; i ++)
 cuenta += (f[n][i].checked) ? 1 : 0;
if (cuenta > maxi) {
  alert("no puede seleccionar más de " + maxi + " elementos");
  c.checked = false;
  --cuenta;
 }
 f.contador.value = cuenta;
}
</script>
</head>
<body>
<form action="" >
<input type="checkbox" name="ch" value="1" onclick="registra(this)" />
<!-- aquí el resto de los checks ... -->
<input type="checkbox" name="ch" value="1" onclick="registra(this)" />
<input type="checkbox" name="ch" value="1" onclick="registra(this)" />
<input type="checkbox" name="ch" value="1" onclick="registra(this)" />
<input type="checkbox" name="ch" value="1" onclick="registra(this)" />
<input type="checkbox" name="ch" value="1" onclick="registra(this)" />
<input type="checkbox" name="ch" value="1" onclick="registra(this)" />
<br />
<input type="text" name="contador" value="0" />
</form>
</body>
</html>
Saludos
__________________
Por favor:
No hagan preguntas de temas de foros en mensajes privados... no las respondo