Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 530
  • Last Modified:

Saving JQuery Sortable Results

Using JQuery Sortable to drag and drop images on a page in the order I want them to appear.

After the user is done sorting, I want a save button that will save the results to a database.  Each li element would have an id, and it would be that id I would want to save as well as the position of that element (ie:  Position 1, 2, 3, etc..)

Any help would be appreciated.

Thanks
0
cartch2008
Asked:
cartch2008
1 Solution
 
BuggyCoderCommented:
assuming your button id is btnTest, here is the jquery to get the value of all the li elements under say a ul with id ulTest

var liData;
$('#btnTest').click(function(){
$('$ulTest li').each(function(index){
liData = liData + '{index:' + index + ';Id:' + $(this).attr('id') + ';}'
});
$.post("yoururl", { data: liData },
  function(data){
    alert("Hello");
  }, "json");

});

Open in new window


Data would be in the following format:-

{index:0;Id:1;}{index:1;Id:2;} and so on
0
 
cartch2008Author Commented:
This would work, so I'll give the points, but, I found a much easier way to do it.  Create a form, store the id's in hidden fields.  The values are submitted in the order that they are sorted in.  I didn't think they would be, that is why I was looking for a jquery solution.  But, they are!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now