I'm trying to get the value of a field from a table created with Ajax. With the function below, all fields with the name qtde
appear, including what I need. I need to make a simple account of a typed field less this created ( qtde - qtde_trans
), but it's complicated.
Function that takes all fields with the name qtde:
$("input[name^='qtde']").each(function() {
console.log($(this).val());
});
Return (the value I want, in the line of calculation, is 2000):
EntirefunctionthatI'mtesting(withthis.valIgetthetypefieldqtde_trans
):
functioncalc_dif(){if($(this).val().length>0){vartotal=$(this).val();$("input[name^='qtde']").each(function() {
console.log($(this).val());
});
if ($("#qtde").val() < $("#qtde_trans").val()) {
alert("Menor");
}else{
alert(total2);
}
}
}
$(function() {
var $table = $('#locais');
$table.on('change', '.input', calc_dif);
$("#qtde_trans").on('change', calc_dif);
});
How the table is created:
for(var i = 0;i<data.length;i++){
HTML += "<tr><td><input type = 'text' size = '3' name = 'status[]' id = 'status[]' value=" + data[i].status + " readonly></td>";
HTML += "<td><input type = 'text' size = '5' name = 'lote[]' id = 'lote[]' value=" + data[i].lote + " readonly></td>";
HTML += "<td><input type = 'text' size = '10' name = 'endereco[]' id = 'endereco[]' value=" + data[i].endereco + " readonly></td>";
HTML += "<td><input type = 'text' size = '6' name = 'validade[]' id = 'validade[]' value=" + data[i].validade + " readonly></td>";
HTML += "<td><input type = 'text' size = '2' name = 'qtde[]' id = 'qtde[]' value=" + data[i].qtde + " readonly></td>";
HTML += "<td><input type = 'number' style = 'width: 25px;' name = 'qtde_trans[]' id = 'qtde_trans[]' class='input'></td></tr>";
}
Example of the table that loads according to the bank's data: