I have done this http://jsbin.com/UBezOVA/1/edit.
When I click the submit button, i want to get the current order of the list item. But, it seems that
$(\"#sortab
Part of your issue is a typographical error, omitting the #
from the id in your jQuery selector. Otherwise, your usage of .sortable("toArray")
is correct. (Note, I used console.log()
there instead of alert()
- watch the browser's console for better output)
function submit(){
var idsInOrder = $("#sortable2").sortable("toArray");
//-----------------^^^^
console.log(idsInOrder);
}
However, as documented the toArray()
method will use the id
attribute of sortable items by default when serializing. You will need to add a unique id
attribute to each of the sortable items for this to work:
- Item 1
- Item 2
- Item 3
- Item 4
- Item 5
Put those two together and it will work as you expect: http://jsbin.com/UBezOVA/6/edit