Foros del Web » Programando para Internet » Javascript »

sumar input tiempo real

Estas en el tema de sumar input tiempo real en el foro de Javascript en Foros del Web. Hola amigos. soy nuevo en javascript y estoy buscando algo que haga suma en tiempo real de lo que yo meta en unos input... al ...
  #1 (permalink)  
Antiguo 03/10/2013, 23:46
Avatar de arcanisgk122  
Fecha de Ingreso: junio-2010
Mensajes: 755
Antigüedad: 13 años, 10 meses
Puntos: 28
Pregunta sumar input tiempo real

Hola amigos.
soy nuevo en javascript y estoy buscando algo que haga suma en tiempo real de lo que yo meta en unos input... al estilo factura

input 1* input2 = input3
input 4* input5 = input6

input7=input3+input6
variable =(input7/100)*7 " impuesto redondear a 2 decimales para arriba"

input8=input7+variable

si alguien tiene algún ejemplo de estos cálculos por favor le agradezco me los pasen para estudiarlos y hacer una tarea de contabilidad computarizada

creo que tiene que ver con ajax pero ni idea
__________________
Cooler Master Gladiator 600 - AMD PHENOM II X4 955 @ 3.5GHZ
GA-MA78GM-US2H - Super Talent 800 2GB x 2 Dual, (Unganged)
PSU Cooler Master eXtreme Power Plus 500W - Saphire R7-260OC-2GB
  #2 (permalink)  
Antiguo 04/10/2013, 05:53
Colaborador
 
Fecha de Ingreso: marzo-2008
Ubicación: Sabadell
Mensajes: 4.897
Antigüedad: 16 años, 1 mes
Puntos: 574
Respuesta: sumar input tiempo real

Un ejemplo

Código HTML:
Ver original
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <title>Documento sin t&iacute;tulo</title>
  3. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  4. <script language="JavaScript" type="text/JavaScript">
  5. function suma(){
  6.     var total=0;
  7.     for (var i=0;i<5;i++){
  8.        total+=parseFloat(document.getElementById("input"+i).value);
  9.     }
  10.     document.getElementById('divBase').innerHTML=total;
  11.     document.getElementById('divIVA').innerHTML=total*parseFloat(document.getElementById("tpiva").value)/100;
  12.     document.getElementById('divTotal').innerHTML=total*(1+parseFloat(document.getElementById("tpiva").value)/100);
  13. }
  14. </head>
  15. <input name="input0" id="input0" type="text" value="0" onBlur="suma()"><br>
  16. <input name="input1" id="input1" type="text" value="0" onBlur="suma()"><br>
  17. <input name="input2" id="input2" type="text" value="0" onBlur="suma()"><br>
  18. <input name="input3" id="input3" type="text" value="0" onBlur="suma()"><br>
  19. <input name="input4" id="input4" type="text" value="0" onBlur="suma()"><br>
  20. Base&nbsp;<span id="divBase">0</span><br>
  21. TpIVA&nbsp;<input name="tpiva" id="tpiva" type="text" value="21" onBlur="suma()"><br>
  22. IVA&nbsp;<span id="divIVA">0</span><br>
  23. Total&nbsp;<span id="divTotal">0</span>
  24. </body>
  25. </html>
__________________
Quim
--------------------------------------------------
Ayudar a ayudar es una buena práctica!!! Y da buenos resultados.
  #3 (permalink)  
Antiguo 04/10/2013, 15:27
Avatar de arcanisgk122  
Fecha de Ingreso: junio-2010
Mensajes: 755
Antigüedad: 13 años, 10 meses
Puntos: 28
Respuesta: sumar input tiempo real

gracias pruebo pero me genera como 15 digitos decimales y solo necesito 3 y ese tercer siempre eliminarlo y si es mayor a 5 sumar+1 al segundo digito ...
algo como 15.216 convertirlo a 15.22
__________________
Cooler Master Gladiator 600 - AMD PHENOM II X4 955 @ 3.5GHZ
GA-MA78GM-US2H - Super Talent 800 2GB x 2 Dual, (Unganged)
PSU Cooler Master eXtreme Power Plus 500W - Saphire R7-260OC-2GB
  #4 (permalink)  
Antiguo 06/10/2013, 11:59
Avatar de blancoarnau  
Fecha de Ingreso: junio-2013
Mensajes: 119
Antigüedad: 10 años, 10 meses
Puntos: 0
Respuesta: sumar input tiempo real

Usa el objeto Math.round():

Código Javascript:
Ver original
  1. function suma(){
  2.     var total=0;
  3.     for (var i=0;i<5;i++){
  4.        total+=parseFloat(document.getElementById("input"+i).value);
  5.     }
  6.     document.getElementById('divBase').innerHTML=Math.round(total);
  7.     document.getElementById('divIVA').innerHTML=Math.round(total*parseFloat(document.getElementById("tpiva").value)/100);
  8.     document.getElementById('divTotal').innerHTML=Math.round(total*(1+parseFloat(document.getElementById('tpiva').value)/100));
  9. }
  10.  
  11. }
  #5 (permalink)  
Antiguo 08/10/2013, 20:33
Avatar de arcanisgk122  
Fecha de Ingreso: junio-2010
Mensajes: 755
Antigüedad: 13 años, 10 meses
Puntos: 28
Respuesta: sumar input tiempo real

pero esto solo trabaja en chrome en ie no
... tenia bloqueado los javascript al terminar la calculadora de factura la dejare para que tengan plantilla
__________________
Cooler Master Gladiator 600 - AMD PHENOM II X4 955 @ 3.5GHZ
GA-MA78GM-US2H - Super Talent 800 2GB x 2 Dual, (Unganged)
PSU Cooler Master eXtreme Power Plus 500W - Saphire R7-260OC-2GB

Etiquetas: ajax, input, real, tiempo, variable
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 06:43.