0

I'm using jQueryUI Sortable and connectWith to allow the dragging and dropping of items between 3 unordered lists.

Each list item contains a string and a value, and has an ID assigned. When the drag-drop has been completed, I want to sum the values of each item in each list and display the total at the bottom of each list.

I could do this with an AJAX call but at the moment, I can't quite get the data I need in a format I want from the lists.

Ideally, I'd like to get an array containing the UL ID's, that in turn contain an associative array containing the ID of the list item as the key and the numerical value from within it. I'm hoping by assigning an ID to the div that contains the numerical value within each LI, I can somehow extract it.

Any advice or pointers greatly appreciated.

Thank you.

jsFiddle here

The Fiddle outputs to the console.

stech
  • 33
  • 1
  • 8

1 Answers1

0

I've adjusted that fiddle and gotten it to total things up for you: http://jsfiddle.net/HNxZU/32/

It doesn't do any array stuff, but hopefully you could just grab the totals with the selected ('li.ui-state-disabled'). Let me know how you get on.

Wil
  • 4,887
  • 3
  • 22
  • 30
  • Thanks Wil, that's amazing... greatly appreciate the tips in your website too. That gets the totals without needing an AJAX call which is great. I also need to be able to save back the new lists to a database, which will require AJAX and will rely on the ID of each LI. I'll see if I can work out how to do that. – stech Aug 01 '12 at 19:56
  • In that case, have a look at this thread http://stackoverflow.com/questions/2936999/howto-serialize-multiple-lists-with-jquery it looks like just what you need. – Wil Aug 01 '12 at 21:20
  • Thanks, I've seen that thread but it was earlier in the learning process and I didn't really understand it! Will give it a more detailed look. – stech Aug 02 '12 at 14:04