Ver Mensaje Individual
  #1 (permalink)  
Antiguo 21/04/2012, 14:28
Montes28
 
Fecha de Ingreso: septiembre-2010
Mensajes: 1.853
Antigüedad: 13 años, 7 meses
Puntos: 6
Contar el numero de checkbox activos

hola amigos del espero me puedan ayudar

estoy enviando un formulario mediante ajax y necesito saber el Contar el numero de checkbox activos.

tengo el siguiente codigo

Código Javascript:
Ver original
  1. $.ajax({
  2.                   url:'archivo.php',
  3.                   type:'post',
  4.                   data:{ nombre: nombre,
  5.                    
  6.                   }

Código Javascript:
Ver original
  1. <script type="text/javascript">
  2. function calcular(obj, opc){
  3.     if(opc==1)
  4.         obj.checked = (document.getElementById("chk_todos").checked==true)?true:false;
  5.     var val = (obj.checked == true)? obj.id.split("_")[1] : 0;
  6.     obj.value = val;
  7.     //document.getElementById("text_"+ obj.id.split("_")[1]).value = val;
  8.    
  9. }
  10.  
  11. function calcularTodos(){
  12.     for(var i = 0 ; i < document.getElementsByName("chk").length; i++)
  13.         calcular(document.getElementsByName("chk")[i], 1);
  14.        
  15.        
  16.        
  17. }
  18.  
  19. </script>
  20.  
  21. [HIGHLIGHT="HTML"]
  22.  
  23. <form>
  24.     <label for="name">Nombre</label>
  25.         <input type="text" name="nombre" id="nombre" class="text ui-widget-content ui-corner-all" />
  26. <table width="747" border="0" id="users" >
  27.   <tr>
  28.     <td width="244"><label>
  29.       <input type="checkbox" name="chk" value="1" id="chk" onclick='calcular(this,0);'/>
  30.       Opcion 1
  31.     </label></td>
  32.     </tr>
  33.   <tr>
  34.     <td><label>
  35.       <input type="checkbox" name="chk" value="4" id="chk" onclick='calcular(this,0);'/>
  36.       Opcion  2 </label></td>
  37.     </tr>
  38.   <tr>
  39.     <td><label>
  40.       <input type="checkbox" name="chk" value="7" id="chk" onclick='calcular(this,0);'/>
  41.       Opcion 3 </label></td>
  42.     </tr>
  43.   <tr>
  44.     <td><label>
  45.       <input type="checkbox" name="chk" value="10" id="chk" onclick='calcular(this,0);'/>
  46.       Opcion 3</label></td>
  47.     </tr>
  48.   <tr>
  49.     <td><label>
  50.       <input type="checkbox" name="chk" value="13" id="chk" onclick='calcular(this,0);'/>
  51.       Opcion 3</label></td>
  52.     </tr>
  53.   <tr>
  54.     <td><label>
  55.       <input type="checkbox" name="chk" value="16" id="chk" onclick='calcular(this,0);'/>
  56.       Opcion 3</label></td>
  57.     </tr>
  58.   <tr>
  59.     <td><label>
  60.       <input type="checkbox" name="chk" value="19" id="chk" onclick='calcular(this,0);'/>
  61.       Opcion 3</label></td>
  62.     </tr>
  63.   <tr>
  64.     <td><label>
  65.       <input type="checkbox" name="chk" value="22" id="chk" onclick='calcular(this,0);'/>
  66.       Opcion 3</label></td>
  67.     </tr>
  68.   <tr>
  69.     <td><label>
  70.       <input type="checkbox" name="chk" value="25" id="chk" onclick='calcular(this,0);'/>
  71.       Opcion 3</label></td>
  72.     </tr>
  73.   <tr>
  74.     <td><input type="checkbox" name="chk" value="28" id="chk" onclick='calcular(this,0);'/>
  75.       Opcion 3</td>
  76.     </tr>
  77.   <tr>
  78.     <td><input type="checkbox" name="chk" value="31" id="chk" onclick='calcular(this,0);'/>
  79.       Opcion 3</td>
  80.     </tr>
  81.   <tr>
  82.     <td><input type="checkbox" name="chk" value="34" id="chk" onclick='calcular(this,0);'/>
  83.       Opcion 3</td>
  84.     </tr>
  85.   <tr>
  86.     <td>&nbsp;</td>
  87.     </tr>
  88.   <tr>
  89.     <td><label>
  90.     <div align="center">
  91.       <input name="checkbox" type='checkbox' id='chk_todos' onclick="calcularTodos();" value="checkbox" />
  92.     </div>
  93.     </label>
  94.       <div align="center">todos</div></td>
  95.     </tr>
  96. </table>
  97.     </fieldset>
  98. </form>
[/HIGHLIGHT]