Ver Mensaje Individual
  #4 (permalink)  
Antiguo 10/01/2014, 02:42
bathorz
 
Fecha de Ingreso: agosto-2013
Mensajes: 150
Antigüedad: 11 años, 5 meses
Puntos: 29
Respuesta: Problemas con radio buton

Puedes sacar una idea de esto:
Código HTML:
Ver original
  1. <script type="text/javascript">
  2.  
  3.   function prueba() {
  4.     var tot1 = 0;
  5.     var tot2 = 0;
  6.     //
  7.     var oRadio1 = document.getElementsByName('c0');
  8.     for (var i = 0; i < oRadio1.length; i++) {
  9.      if (oRadio1[i].checked) {
  10.        tot1 += parseFloat(oRadio1[i].value);
  11.      }
  12.    }
  13.    //
  14.    var oRadio2 = document.getElementsByName('c1');
  15.    var mas2 = 0;
  16.    for (var i = 0; i < oRadio2.length; i++) {
  17.      if (oRadio2[i].checked) {
  18.        tot2 += parseFloat(oRadio2[i].value);
  19.        mas2 += parseFloat(2);
  20.      }
  21.    }
  22.    //
  23.    document.getElementById("total1").value = tot1;
  24.    document.getElementById("total2").value = tot2;
  25.    //
  26.    document.getElementById("suma1").innerHTML = tot1;
  27.    document.getElementById("suma2").innerHTML = tot2;
  28.    document.getElementById("suma3").innerHTML = tot1 - mas2;
  29.  }
  30.  
  31. <form id="form1" name="Prueba" method="post" action="">
  32.   <table width="289" border="1">
  33.     <tr class="centrado">
  34.       <td width="144">Siempre</td>
  35.       <td width="129">Con frecuencia</td>
  36.     </tr>
  37.     <tr>
  38.       <td><input type="checkbox" name="c0"
  39.                 onClick="prueba()" value="2.00" id="c0_1" />
  40.       </td>
  41.       <td><input type="checkbox" name="c1"
  42.                 onClick="prueba()" value="1.34" id="C1_1" />
  43.       </td>
  44.     </tr>
  45.     <tr>
  46.       <td><input type="checkbox" name="c0"
  47.                 onClick="prueba()" value="2.00 " id="c0_2" />
  48.       </td>
  49.       <td><input type="checkbox" name="c1"
  50.                 onClick="prueba()" value="1.34" id="C1_2" />
  51.       </td>
  52.     </tr>
  53.     <tr>
  54.       <td><input type="checkbox" name="c0"
  55.                 onClick="prueba()" value="2.00" id="C0_3" />
  56.       </td>
  57.       <td><input type="checkbox" name="c1"
  58.                 onClick="prueba()" value="1.34" id="C1_3" />
  59.       </td>
  60.     </tr>
  61.     <tr>
  62.       <td><input type="checkbox" name="c0"
  63.                 onClick="prueba()" value="2.00" id="C0_4" />
  64.       </td>
  65.       <td><input type="checkbox" name="c1"
  66.                 onClick="prueba()" value="1.34" id="C1_4" />
  67.       </td>
  68.     </tr>
  69.     <tr>
  70.       <td><input type="checkbox" name="c0"
  71.                 onClick="prueba()" value="2.00" id="C0_5" />
  72.       </td>
  73.       <td><input type="checkbox" name="c1"
  74.                 onClick="prueba()" value="1.34" id="C1_5" />
  75.       </td>
  76.     </tr>
  77.   </table>
  78.   <p>&nbsp;</p>
  79.   <input type="text" name="suma1" value="0" id="total1">
  80.   <input type="text" name="suma2" value="0" id="total2" />
  81. </form>
  82. Parcial c1:<div id="suma1">0</div>
  83. Parcial c2:
  84. <div id="suma2">0</div>
  85. Total:
  86. <div id="suma3">0</div>