Ver Mensaje Individual
  #4 (permalink)  
Antiguo 26/07/2010, 15:05
Avatar de Adler
Adler
Colaborador
 
Fecha de Ingreso: diciembre-2006
Mensajes: 4.671
Antigüedad: 17 años, 4 meses
Puntos: 126
Respuesta: Poner el total en formato de moneda

Hola
Veamos así
Código Javascript:
Ver original
  1. <html xmlns="http://www.w3.org/1999/xhtml">
  2. <head>
  3. <script>
  4. var total=0;
  5. function operaciones(bol, valor) {
  6. if (bol) {
  7. total += valor;
  8.  
  9. } else {
  10. total-=valor;
  11. }
  12.  
  13. var entero = '';
  14.  
  15. Entero_Decimal = total.toString().split('.');
  16.  
  17. cadena = Entero_Decimal[0].split('').reverse().join('');
  18.  
  19. for (var z = cadena.length; z >=0; z--) {
  20. numero = cadena.charAt(z)
  21. if ((cadena.length >= 4 && z ==3 ) || (cadena.length >= 7 && z ==6 ) || (cadena.length >= 10 && z == 9 ) || (cadena.length >= 13 && z ==12 ) || (cadena.length >= 16 && z ==15 )) {
  22. numero +=  ".";
  23. }
  24.  
  25. entero += numero;
  26. }
  27.  
  28. if(Entero_Decimal[1]) {decimales = ','+ Entero_Decimal[1];}else{decimales='';}
  29.  
  30. document.formulario.total.value=entero + decimales;
  31.  
  32. }
  33.  
  34.  
  35.  
  36. </script>
  37. </head>
  38.  
  39. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  40. <title>Documento sin t&#237;tulo</title>
  41. </head>
  42.  
  43. <body>
  44. <form name=formulario>
  45. <input name="checkbox" type="checkbox" onClick="operaciones(this.checked,1000.98)" value="checkbox">$1,000.98<br>
  46. <input name="checkbox" type="checkbox" onClick="operaciones(this.checked,2000.50)" value="checkbox">$2,000.50<br>
  47. <input type="text" name="total" value="0">
  48. </form>
  49. </body>
  50. </html>
Suerte
__________________
Los formularios se envían/validan con un botón Submit
<input type="submit" value="Enviar" style="background-color:#0B5795; font:bold 10px verdana; color:#FFF;" />