jquerysequencesortables

jQuery sortables


I'm using the sortable function in jquery to sequence a faq list. Needless to say, i'm new to this concept. Anybody have any good examples of the backend for this. I have the front working fine, but updating the sequence in the database is another story. My backend is ColdFusion btw.

Thanks in advance


Solution

  • Define the faq:

    <div id="faq">
      <div id="q1">...</div>
      <div id="q2">...</div>
      (...)
      <div id="q100">..</div>
    </div>
    

    Make faq sortable:

    <script type="text/javascript">
      $("#faq").sortable();
    </script>
    

    Form submitted:

    <form action="..." id="faq_form">
      <input type="hidden" name="faqs" id="faqs" />
      ...
    </form>
    

    Add sorted sequence to form

    <script type="text/javascript>
      $("#faq_form").submit(function() {
        $("#faqs").val($("#faq").sortable('toArray'))
      })
    </script>
    

    When form is submitted, field "faqs" will contain comma separated id's from #faq like this: q1,q3,q10,q11,q2,q100...

    Just parse it and save to DB