I have some code that will gather up the sort of a sortable list and turn it into an array. The code is set up to work on the drop event, so when you drag an item and then drop it the array is created and sent out. I need to change this so that it is triggered by a button click instead, for some reason turning this into a click event will not work though.
Here is the function as it is now
$(document).ready(function(){
$('#sortable-stages').sortable({
update: function(event, ui) {
var stage = document.getElementsByClassName('stage');
var stageOrder = $(this).sortable('toArray');
$.get('/stages/reorder', { 'order' : stageOrder });
}
});
});
Any help on how to turn this code into something that is triggered by a button click would be great.
I did try the obvious
$(document).on('click','#stagereorderbutton', function() {
//...
});
and that did not run the code even though it would trigger an alert, but only if placed right at the beginning, above the update: part.