Ver Mensaje Individual
  #5 (permalink)  
Antiguo 01/12/2011, 16:25
Avatar de jor_0203
jor_0203
 
Fecha de Ingreso: octubre-2011
Ubicación: mexico
Mensajes: 760
Antigüedad: 12 años, 6 meses
Puntos: 8
Respuesta: como puedo seleccionar todos los checkbox de forma dinámica

puse esto y no me funciona y si me funciona cuando pongo solo un dato checked="checked" pero si lo borro y ninguna casilla esta activada no me funciona
mil gracias

Código Javascript:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Documento sin t&iacute;tulo</title>
  6.  
  7.  
  8.  
  9. <script type="text/javascript">
  10.     function selectall(form)
  11.     {
  12.      var formulario = eval(form)
  13.      for (var i=0, len=formulario.elements.length; i<len ; i++)
  14.       {
  15.         if ( formulario.elements[i].type == "checkbox" )
  16.           formulario.elements[i].checked = formulario.elements[0].checked
  17.       }
  18.     }
  19. </script>
  20. </head>
  21.  
  22. <body>
  23. <form id="form1" name="form1" method="post" action="">
  24. <input name="a" type="checkbox"/>
  25. <br />
  26. <input type="checkbox" name="b" />
  27. <br />
  28. <input type="checkbox" name="c" />
  29. <br />
  30. <input type="checkbox" name="d"/>
  31. <br />
  32. <input type="submit" name="button" value="seleccionar todos" />
  33. </form>
  34. <input type="checkbox" onclick="selectall(document.forms[0])" />
  35.  
  36. </body>
  37. </html>