Ver Mensaje Individual
  #2 (permalink)  
Antiguo 01/12/2009, 15:10
Avatar de nicolaspar
nicolaspar
 
Fecha de Ingreso: noviembre-2004
Ubicación: Villa Ballester Bs-As|Ar
Mensajes: 2.002
Antigüedad: 20 años, 2 meses
Puntos: 34
Respuesta: sumar el valor de los checkbox seleccionados

Hola lexus!. Primero, trata de no usar "ke" o términos como "chuleando/deschulearlo". Ayuda a la lectura y a ayudarte.

En si, en cada evento onlick de tus checks tendrás que llamar a una función (para que quede lindo):

Código html:
Ver original
  1. <form name="miform" id="miform">
  2. ...
  3. <input name="id" type="checkbox" id="clt" value="..." onclick="sumar()" />
  4. ...
  5. </form>

Luego, la función sería:
Código javascript:
Ver original
  1. function sumar(){
  2.     obj = document.miform['id'];
  3.     totalChecks = obj.length;
  4.     totalSumado = 0;
  5.     for( i=0; i<totalChecks; i++){
  6.         if( obj[i].checked == true ){
  7.             valor = obj[i].value.split('-');       
  8.             totalSumado = totalSumado + parseInt(valor[0],10);
  9.         }
  10.     }
  11.     alert('estás sumando: '+ totalSumado);
  12. }



El ejemplo completo:
Código html:
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. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>Ejemplo</title>
  5. <script language="javascript" type="text/javascript">
  6. function sumar(){
  7.     obj = document.miform['id'];
  8.     totalChecks = obj.length;
  9.     totalSumado = 0;
  10.     for( i=0; i<totalChecks; i++){
  11.         if( obj[i].checked == true ){
  12.             valor = obj[i].value.split('-');       
  13.             totalSumado = totalSumado + parseInt(valor[0],10);
  14.         }
  15.     }
  16.     document.getElementById('informacion').innerHTML = 'estás sumando: '+ totalSumado;
  17. }
  18. </head>
  19.  
  20. <div id="informacion">estás sumando: 0</div>
  21. <form name="miform" id="miform">
  22.     1<input name="id" id="clt" type="checkbox" value="1500-abcd" onclick="sumar()" /><br>
  23.     2<input name="id" id="clt" type="checkbox" value="2500-abcd" onclick="sumar()" /><br>
  24.     3<input name="id" id="clt" type="checkbox" value="3500-abcd" onclick="sumar()" /><br>
  25.     4<input name="id" id="clt" type="checkbox" value="4500-abcd" onclick="sumar()" /><br>
  26. </form>
  27. </body>
  28. </html>


Espero que te sirva.
__________________
Mi punto de partida es Que Bueno Lo Nuevo