Ver Mensaje Individual
  #4 (permalink)  
Antiguo 19/02/2014, 19:24
jiten
 
Fecha de Ingreso: febrero-2008
Mensajes: 409
Antigüedad: 16 años, 2 meses
Puntos: 2
Respuesta: Desactivar checkboxes cuando se clickean 5 de ellos

Cita:
Iniciado por America|UNK Ver Mensaje
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>
no funciona....