1
I was able to dynamically generate a table with some hidden fields that cannot appear. But I’m having difficulty searching these fields to send them to a post. Follow the generated html code.
<tr>
<td>Tenis Azul</td>
<td>35</td>
<td>99.99</td>
<td>Admin</td>
<td><input type="checkbox" value="true"></td>
<td><a class="botao-remover btn btn-danger glyphicon glyphicon-trash" href="#"></a></td>
<input type="hidden" value="1">
<input type="hidden" value="35">
<input type="hidden" value="99.99">
<input type="hidden" value="1">
<input type="hidden" value="1">
</tr>
I have several generated like this. But when selecting values I don’t know how to search to store in variables. I’ve tried . attr("value"). val() but not for sure.
var linhas = $("tbody>tr");
linhas.each(function(){
var id_produto = $(this).find("input:nth-child(1)").attr("value").val();
console.log(id_produto);
});
Error:
Uncaught TypeError: $(...).find(...).attr(...).val is not a function
Can anyone help me? Thanks in advance
If sent by POST by a
<form>
would just assign aname
the inputs that the form itself would send to the server.– fernandosavio
Dude, it hasn’t even crossed my mind. I think it settles it quietly. I’ll try it here. Thank you
– Bruno
Thinking well the ideal would be to read all the same <tr> and make an array to send by Post.
– Bruno
You don’t have to read all the tr can take the value of inputs directly.
– LeAndrade
If all inputs have the same
name
the server will receive as an array.– fernandosavio
I can’t read them directly, because I create them dynamically to fill a row of a table. If my table generates 10 row for example will be 50 inputs. I don’t see how to read directly because the intention is to take these lines later and insert them into the database
– Bruno