I have the code below that handle should get the values of a TexBox inside a table that is generated dynamically by another JQuery function. The problem is that this code always brings the TextBox value of the first line.
$('#tbl').on('focusout', '.vlr', function(event){
var $qtd = $('tr').find('.qtda').val();
var $valor = $('tr').find('.vlr').val();
if ($qtd > 0 && $qtd != "") {
if ($valor > 0 && $valor != "") {
var $total = $qtd * $valor;
$('.vlrTotal').closest().text($total)
}
else {
$('.vlr').val('0');
}
}
else {
$('.vlr').val('0');
}
})
Edited:
Function code that generates the table:
function Pesquisar(){
$('.corpoTbl').remove();
$.ajax({
url: "/RCM/ListarMateriais",
type: "POST",
data: { nome: $('#Pesquisar').val() },
datatype: 'json',
success: function (data) {
$.each(data, function (I, item) {
$('#tbl').append("<tr class=\"corpoTbl\"> <td class=\"ids\">" + item.ID + "</td><td id=\"nome\">" + item.Nome + "</td><td id=\"unidade\"><center>" + item.Unidade +
"</center></td><td> <center><input class=\"qtda\" type=\"text\" value=\"0\" style=\"width: 50px;\" /></center></td><td> " +
"<center><input class=\"vlr\" type=\"text\" value=\"0\" style=\"width: 50px;\" /></center> </td><td class=\"vlrTotal\"></td><td> <center><i class=\"icon-plus\"></i></center> </td></tr>")
})
}
});
}