Ver Mensaje Individual
  #4 (permalink)  
Antiguo 15/12/2011, 07:58
marcofbb
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: Incremento de variable Ajax y checkbox

Fijate si te sirve este codigo, para deducir una solucion:

Código HTML:
Ver original
  1. <script language="javascript">
  2. function sumar(sel) {
  3.     var obj, sel, precio, obj2;
  4.     precio = 0;
  5.     obj = document.forml['campo[]'];
  6.     for (i = 0; lcheck = obj[i]; i++) {
  7.         if(obj[i].checked){
  8.             precio += parseInt(obj[i].value);
  9.         }
  10.        
  11.     }
  12.     document.getElementById('precio').innerHTML = precio;
  13. }
  14.  
  15.  
  16. <form action="" method="post" name="forml" >
  17. <input name="campo[]" type="checkbox" value="1" onClick="sumar(this)">
  18. <input name="campo[]" type="checkbox" value="2" onClick="sumar(this)">
  19. <input name="campo[]" type="checkbox" value="3" onClick="sumar(this)">
  20. <input name="campo[]" type="checkbox" value="4" onClick="sumar(this)">
  21. <div id="precio"></div>
  22. </form>