In each row of the table I have an input, I need to change the value of the input with the value of the line position. How can I do this?
$(document).ready(function () {
$('tbody').sortable({
axis: 'y',
containment: 'parent',
change: function(){
console.log("change");
$.each($(".tab_dados tbody>tr"), function(indice, obj){
$(this).find($("td>input[type=text]")).val(indice + 1);
});
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.js"></script>
<table class="tab_dados">
<thead>
<tr>
<th style="width: 30px;"></th>
<th>CÓDIGO</th>
<th>NOME</th>
<th>input</th>
</tr>
</thead>
<tbody>
<tr>
<td> </td>
<td>25</td>
<td>HUGO</td>
<td><input type="text" name="id25" value="1"></td>
</tr>
<tr>
<td> </td>
<td>26</td>
<td>bruno</td>
<td><input type="text" name="id26" value="2"></td>
</tr>
<tr>
<td> </td>
<td>27</td>
<td>rafael</td>
<td><input type="text" name="id27" value="3"></td>
</tr>
</tbody>
</table>