Ver Mensaje Individual
  #5 (permalink)  
Antiguo 30/06/2010, 07:15
Avatar de Adler
Adler
Colaborador
 
Fecha de Ingreso: diciembre-2006
Mensajes: 4.671
Antigüedad: 17 años, 4 meses
Puntos: 126
Respuesta: Ayuda problema obtener checkbox seleccionados

Hola

Prueba con este

Código Javascript:
Ver original
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <script type="text/javascript">
  5. function valores(f) {
  6. cual1 = 'c[]';
  7. cual2 = 'c2[]';
  8. todos = new Array();
  9. for (var i = 0, total = f[cual1].length; i < total; i++) {
  10.     if (f[cual1][i].checked) todos[todos.length] = f[cual1][i].value;
  11. }
  12.  
  13. for (var i = 0, total = f[cual2].length; i < total; i++) {
  14.     if (f[cual2][i].checked) todos[todos.length] = f[cual2][i].value;
  15. }
  16. document.getElementById('sel').value = todos.join(', ');
  17. }
  18. </script>
  19. </head>
  20. <body>
  21. <form>
  22. <div id="m_c1">
  23. <input name="c[]" type="checkbox" value="0" />
  24. <input name="c[]" type="checkbox" value="1" />
  25. <input name="c[]" type="checkbox" value="2" />
  26. <input name="c[]" type="checkbox" value="3" />
  27. <input name="c[]" type="checkbox" value="4" />
  28. <input name="c[]" type="checkbox" value="5" />
  29. </div>
  30. <div id="m_c2">
  31. <input name="c2[]" type="checkbox" value="6" />
  32. <input name="c2[]" type="checkbox" value="7" />
  33. <input name="c2[]" type="checkbox" value="8" />
  34. <input name="c2[]" type="checkbox" value="9" />
  35. <input name="c2[]" type="checkbox" value="10" />
  36. <input name="c2[]" type="checkbox" value="11" />
  37. </div>
  38.  
  39. <input type="button" onclick="valores(this.form);" value="mostrar" />
  40. <input type="text" id="sel" value="" />
  41. </form>
  42. </body>
  43. </html>

Suerte
__________________
Los formularios se envían/validan con un botón Submit
<input type="submit" value="Enviar" style="background-color:#0B5795; font:bold 10px verdana; color:#FFF;" />