As the example below, I'm trying to sum the values of the Qtde Transferir
lines, which are dynamically generated as the result of the database, subtract from the value entered in the Quantidade a Transferir
field and display the difference in the% p>
I'vebuiltthecodebelow,usingsomeexamplesIfound,itaddedthedynamicrows,butfirstIneedtoenterthevaluesintherowsandfinallytheFalta
tocalculatetheQuantidadeaTransferir
:
$(document).ready(function(){$("#qtde_entrada").on('change', function() {
if($(this).val().length > 0) {
var total = 0;
$('.input').each(function(){
var valor = Number($(this).val());
if (!isNaN(valor)) total += valor;
});
var final = $("#qtde_entrada").val() - total;
$("#qtde_falta").val(final);
}
});
});
The inputs are set as follows:
Download and Missing Qty:
<tr>
<td colspan='2'>Quantidade a Transferir:
<input type = "number" id="qtde_entrada" name = "qtde_entrada" min="1" max="99999" style="width: 10em;"> -
<b>Falta: <input type = "number" id="qtde_falta" name = "qtde_falta" class="resultado" style="width: 10em;" readonly></b></td>
</tr>
Download Qty (dynamic):
HTML += "<td><input type = 'text' size = '5' name = 'qtde_trans[]' id = 'qtde_trans[]' class='input' ></td></tr>";
Any suggestions on how you could do to first enter the total amount to be transferred and as you type in the rows it is displaying in the default?