Ver Mensaje Individual
  #2 (permalink)  
Antiguo 14/09/2016, 05:02
kraneok
 
Fecha de Ingreso: noviembre-2010
Ubicación: Córdoba
Mensajes: 119
Antigüedad: 13 años, 5 meses
Puntos: 8
Respuesta: recorrer una tabla y calcular

Suponiendo que usas jQuery. He escrito el código a ciegas, no lo he probado, tendrás que retocarlo.

Código Javascript:
Ver original
  1. //
  2. // Aquí tendremos todos los objetos del DOM tr
  3. var $rows = $('#detall > tbody tr'),
  4.     rowsLength = $rows.length
  5.     total = 0
  6.     $row, $totalRow,
  7.     price, amount, totalProduct;
  8.  
  9. for (var i = 0; i < rowsLength; i++ ) {
  10.   $row = $rows [i];
  11.   $totalRow = $($row).find ('#importe');
  12.  
  13.   price = Number($($row).find('#moneda').val().split(',').join('.'));
  14.   amount = Number($($row).find('#cantidad').val());
  15.   totalProduct = price * amount;
  16.  
  17.   $totalProduct.val(totalProduct);
  18.   total += totalProduct;
  19.  
  20. }