0
I have an html similar to the html below and I need to get the value of an input that is within a sub table who is contained within one another table from the click the Insert button, I saw some posts and could not make it work and returns undefind error:
JQUERY
$(function () {
$(document).on("click", ".btnInsere", function () {
var _id = $('#divSP').find('input[name=txtValor]').data('valor');
});
});
HTML
<div id="divSP">
<table id="tblPrincipal">
<thead>
<th>
<td></td>
<td></td>
</th>
</thead>
<tbody>
<tr>
<td>
<!--Table 1-->
<table>
<thead>
<th>
<td> </td>
<td></td>
</th>
</thead>
<tbody>
<tr>
<td><input type="text" class="txtValor" name="txtValor[]" id="@item.valor" data-valor="@item.valor" value="Arroz"/> </td>
<td><input type="button" class="btnInsere" name="btnInsere" id="btnInsere" value="Insere"/></td>
</tr>
</tbody>
</table>
</tr>
<tr>
<!--Table 2-->
<table>
<thead>
<th>
<td> </td>
<td></td>
</th>
</thead>
<tbody>
<tr>
<td><input type="text" class="txtValor" name="txtValor[]" id="@item.valor" data-valor="@item.valor" value="Feijão"/> </td>
<td><input type="button" name="btnInsere" id="btnInsere" value="Insere"/></td>
</tr>
</tbody>
</table>
</tr>
<tr>
<!--Table n... -->
<table>
<thead>
<th>
<td> </td>
<td></td>
</th>
</thead>
<tbody>
<tr>
<td><input type="text" class="txtValor" name="txtValor[]" id="@item.valor" data-valor="@item.valor" value="Salada"/> </td>
<td><input type="button" name="btnInsere" id="btnInsere" value="Insere"/></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
Missing close the tag
<table id="tblPrincipal"
– Sam