I have a script that counts the number of rows in a table and assigns a value attribute to an input field. I am adding the draggable plugin Sortable to table rows, what would be the best way to run this script then on document ready, and on change. The first part works, but i am not getting alerted when the table rows change.
this is now my revised code:
function countRows(){
    var i = 0;
    $('#offices td input').each(function(){
        $(this).attr("value", ++i);
    });  
}
$(document).ready(countRows);
// Sortable rows
$('.sorted_table').sortable({
  containerSelector: 'table',
  itemPath: '> tbody',
  itemSelector: 'tr',
  placeholder: '<tr class="placeholder"/>'
})
$('.sorted_table').children("tbody").sortable({
    stop: function (event, ui) {
        countRows(); // re-number rows after sorting
    }
});
 
    