Ver Mensaje Individual
  #2 (permalink)  
Antiguo 25/01/2018, 04:30
Avatar de xfxstudios
xfxstudios
 
Fecha de Ingreso: junio-2015
Ubicación: Valencia - Venezuela
Mensajes: 2.448
Antigüedad: 8 años, 10 meses
Puntos: 263
Respuesta: Sumar valores de array

Depende de como esten tus campos, por ejemplo:

Código HTML:
Ver original
  1. <input type="text" class="numero"/><br><br>
  2. <input type="text" class="numero"/><br><br>
  3. <input type="text" class="numero"/><br><br>
  4. <input type="text" class="numero"/><br><br>
  5. <input type="text" class="numero"/><br><br>
  6. <div id="valorCompra">
  7.   Ingrese los montos
  8. </div>

Código Javascript:
Ver original
  1. var total = 0;
  2. $(function(){
  3.   $(".numero").change(function(){
  4.   total = 0;
  5.     $(".numero").each(function(){
  6.       var valor = ($(this).val()!="" && $.isNumeric($(this).val())) ? $(this).val() : 0;
  7.       total = parseFloat(total) + parseFloat(valor);
  8.       $("#valorCompra").html("Total Compra: "+total.toLocaleString("es"));
  9.     })
  10.   })
  11. })

MUESTRA
__________________
[email protected]
HITCEL