Ver Mensaje Individual
  #2 (permalink)  
Antiguo 19/02/2014, 03:27
Avatar de America|UNK
America|UNK
 
Fecha de Ingreso: noviembre-2006
Ubicación: Piura - Perú
Mensajes: 582
Antigüedad: 17 años, 5 meses
Puntos: 56
Respuesta: Desactivar checkboxes cuando se clickean 5 de ellos

Hola, intenta esta forma:

Código Javascript:
Ver original
  1. <input type="checkbox" id="atrib_1" /><br />
  2. <input type="checkbox" id="atrib_2" /><br />
  3. <input type="checkbox" id="atrib_3" /><br />
  4. <input type="checkbox" id="atrib_4" /><br />
  5. <input type="checkbox" id="atrib_5" /><br />
  6. <input type="checkbox" id="atrib_6" /><br />
  7. <input type="checkbox" id="atrib_7" /><br />
  8. <input type="checkbox" id="atrib_8" /><br />
  9. <input type="checkbox" id="atrib_20" /><br />
  10.  
  11. <script>
  12.  
  13. var checkboxes = function(fn){
  14.     var i = 0, box
  15.     while(i <= 20) (box = document.getElementById("atrib_" + i++), box && fn.apply(box,[]))
  16. };
  17.  
  18. checkboxes(function(){
  19.     this.onclick = function(){
  20.         var count = 0
  21.         checkboxes(function(){
  22.             this.checked && count++
  23.         })
  24.         checkboxes(function(){
  25.             !this.checked && count >= 5 ? this.disabled = !0 : this.disabled = !1
  26.         })
  27.     }
  28. });
  29.  
  30.  
  31. </script>
__________________
/* El que atiende, entiende..., el que entiende, aprende!.
Desarrollo Web Freelance, Contactar */