0
I have a dynamic table with columns of quantity of a product and unit value, where I need to multiply the unit value by quantity (Qtd X val_unitario) and at the end display the total sum of the multiplications (according to the image)
$('table input').on('input', function () {
var $tr = $(this).closest('tr');
var tot = 0;
$('input', $tr).each(function () {
tot += parseFloat(($(this).val()).replace(',', '.'));
});
$('td:last', $tr).text(tot);
}).trigger('input');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<table>
<tr id="tr_1">
<td id="td_qtd_produto_1">
<input type="text" id="qtd_produto_1" name="qtd_produto_1" value="5">
</td>
<td id="val_unitario_produto_1">
<input type="text" id="valor_unitario_1" name="valor_unitario_1" value="48,00">
</td>
<td id="td_total_1">
<p id="total_1"></p>
</td>
</tr>
<tr id="tr_2">
<td id="td_qtd_produto_2">
<input type="text" id="qtd_produto_2" name="qtd_produto_2" value="12">
</td>
<td id="val_unitario_produto_2">
<input type="text" id="valor_unitario_2" name="valor_unitario_2" value="6,80">
</td>
<td id="td_total_2">
<p id="total_2"></p>
</td>
</tr>
<tr id="td_total">
<td></td>
<td></td>
<td>
<p id="total_geral"></p>
</td>
</tr>
</table>
How do I perform this calculation?
I was trying to select each input via .each()
but I couldn’t quite understand his application
Ball show! It worked perfectly, my biggest difficulty was understanding how I would take the value of the first input and multiply with the input of the second and make the total.
– Igor Lessa