Ver Mensaje Individual
  #1 (permalink)  
Antiguo 01/10/2009, 11:36
Avatar de tampon
tampon
 
Fecha de Ingreso: julio-2009
Mensajes: 420
Antigüedad: 15 años, 6 meses
Puntos: 0
Pregunta AYUDA con suma de cantidades monetarias

Hola tengo una duda, estoy sumando con selects y me va bien con numero normales, pero al momento de querer sumar numero decimales o numeros que contengan comas y puntos me suma de un mal modo y no me da el resultado correcto, pongo el codigo de un ejemplo..
¿alguien me puede echar la mano con este problema?

Código js:
Ver original
  1. <html><head></head><body>
  2.  
  3. <script language="JavaScript">
  4.  
  5. function Suma1(isChecked, myValue){
  6.     tot = parseInt(document.sumar1.total1.value);
  7.     myValue = parseInt(myValue);
  8.     if (isChecked) document.sumar1.total1.value = tot + myValue;
  9.         else document.sumar1.total1.value = tot - myValue;
  10. }
  11.  
  12. function Suma2(isChecked, myValue){
  13.     tot = parseInt(document.sumar2.total2.value);
  14.     myValue = parseInt(myValue);
  15.     if (isChecked) document.sumar2.total2.value = tot + myValue;
  16.         else document.sumar2.total2.value = tot - myValue;
  17. }
  18.  
  19. </script>
  20.  
  21. <body>
  22. <h1>Aqui esta todo bien</h1>
  23. <form name="sumar1" method="POST">
  24.  
  25.     <p><input type="checkbox" value="63" name="Check1" onClick="Suma1(this.checked,this.value)" >$63</p>
  26.     <p><input type="checkbox" value="50" name="Check2" onClick="Suma1(this.checked,this.value)" >$50</p>
  27.     <p><input type="checkbox" value="1252" name="Check3" onClick="Suma1(this.checked,this.value)" >$1252</p>
  28.     <p><b><font color="#999999">$</font></b> <input id="pago" class="resultado" type="text" name="total1" value="0" disabled></p>
  29.  
  30. </form>
  31. <h1>Aqui no funciona tan bien</h1>
  32. <form name="sumar2" method="POST">
  33.  
  34.     <p><input type="checkbox" value="63.50" name="Check1" onClick="Suma2(this.checked,this.value)" >$63.50</p>
  35.     <p><input type="checkbox" value="50.00" name="Check2" onClick="Suma2(this.checked,this.value)" >$50.00</p>
  36.     <p><input type="checkbox" value="1,252.00" name="Check3" onClick="Suma2(this.checked,this.value)" >$1,252.00</p>
  37.     <p><b><font color="#999999">$</font></b> <input id="pago" class="resultado" type="text" name="total2" value="0" disabled></p>
  38.  
  39. </form>
  40.  
  41. </body></html>