netrox netrox - 1 year ago 72
jQuery Question

serializing sortables not working

I've tried everything and it still fails! What's wrong with this code?!?! I wanted to get the serialized sortable, it's that simple but I've looked on SO and found snippets.. applied with my code and it still doesn't work. It makes no sense at all. I did look at possible errors (and yes, there's set_number as specified by jQuery doc)... but still nothing works.

<script type='text/javascript' src=''>
<script type="text/javascript" src="">

$(function() {
$( "#sortable" ).sortable();
$( "#sortable" ).disableSelection();

$('#thedata').val($( "#sortable" ).sortable("serialize"));
return false;

Filters For Tables
Filters for Assets
<form action="validate.php" method="post">
<input type='text' name='thedata' id='thedata' />
<ul id="sortable">
<li id="foo_0">ID</li>
<li id="foo_1">TIME LOG</li>
<li id="foo_2">DEVICE TYPE</li>
<li id="foo_3">CHASSIS TYPE</li>
<li id="foo_4">PARENT ID</li>
<li id="foo_5">PARENT</li>
<input type="submit" name="submit" id="submit" value="Update" />


Answer Source

The form element does not exist. You have to bind events when the DOM is ready. Just move this:

    $('#thedata').val($( "#sortable" ).sortable("serialize"));
    return false;        

To this function: $(function() {}); It works on JSFiddle because there is JavaScript called when the DOM is loaded I think.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download