0
In each table row I have an input, I need to change the input value with the row position value. 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>
<script src="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>
I didn’t quite understand. could you explain me better.
– Hugo Borges
It was clearer, @Hugoborges?
– Aline
I had tried this and it didn’t work. I even edited the question with your answer. It didn’t log tbm errors.
– Hugo Borges
If you debug js, it stops in the change function?
– Aline
The change function is running, I put a log in to check. The thing that does not occur is the change of the input values. Since they always have to be in order. Ie the 1st input will always be 1, the 2nd will always be 2 and etc...
– Hugo Borges
Just to test, put the type="text" in the inpt. And also change here: $(this). find($("td>input[type=text]"). val(Indice + 1);
– Aline
Ready changed, I put the log for you see tbm. Still not working.
– Hugo Borges
Ready. Just take a look at the documentation for what you’ll need from now on. (=
– Aline
worked out, thank you very much
– Hugo Borges