1
I have the code below that picks up should take the values of a Texbox within 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:
Code of the function generating 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>")
})
}
});
}
would it be possible to post the html of the generated table? otherwise it adds a class in the textbox. and picks it up using $('.suaclass') this will return an array with all elements containing this class.
– leonardo
Leonardo, I added the code that generates the table.
– Alan Almeida
Have you tried this? $("#tbl tr td input.qtda")
– leonardo