views:

450

answers:

2

I am looking at the demo for sorting items here but I want the text in the list to appear as something but when I click save and it posts server side I want to use values. I know <li> doesn't support value so what options do I have?

UPDATE: I assume the way to save the data server side is to have a hidden input, when the user clicks a save button you populate the hidden field with the sortable.array() data with javascript and then it does the post?

A: 

You can use the data- attriute as recommended in HTML5 documentation

<li data-value="the real value">Some Value</li>
peirix
+1  A: 

Inside a form submit handler you can serialize the sortable into a hidden input which will be posted back server side.

In response to your comment - serialize() does indeed work as demo'd here

e.g

$('#yourForm').submit( saveSortable );

function saveSortable(){

  $('#hiddenInput').val( $('#sortable').serialize() );

}
redsquare
$('#sortable').serialize() doesn't return anything
Jon
see http://jqueryui.com/demos/sortable/#method-serialize. Have you changed 'sortable' to the correct id of your element?
redsquare
That would be it! I went with toArray in the end, seems simpler
Jon
I've just realised I need 2 values to post so I have seperated them with a hyphen. Does that make sense. Server side I can then split it.
Jon
either that or two hidden inputs, whatever you feel is best
redsquare