Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 754433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:00:46+00:00 2026-05-14T15:00:46+00:00

Here is an interesting use of JavaScript: reordering items with drag and drop. The

  • 0

Here is an interesting use of JavaScript: reordering items with drag and drop. The implementation itself in my page works fine, but is there a way to determine in which order the user put the items?

I’m asking because I want to load and save the item order in a cookie.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T15:00:46+00:00Added an answer on May 14, 2026 at 3:00 pm

    UPDATED 2012

    FULL WORKING DEMO & SOURCE


    get the index position of the elements try to read this:

    • Getting the position of the element in a list when it's drag/dropped (ui.sortable)

    COOKIE plugin for jquery:

    • http://plugins.jquery.com/project/cookie

    JQUERY:

     $(function() {
        //coockie name
         var LI_POSITION = 'li_position';
           $('ul#sortable').sortable({
             //observe the update event...
                update: function(event, ui) {
                  //create the array that hold the positions...
                  var order = []; 
                    //loop trought each li...
                   $('#sortable li').each( function(e) {
    
                   //add each li position to the array...     
                   // the +1 is for make it start from 1 instead of 0
                  order.push( $(this).attr('id')  + '=' + ( $(this).index() + 1 ) );
                  });
                  // join the array as single variable...
                  var positions = order.join(';')
                   //use the variable as you need!
                  alert( positions );
                 // $.cookie( LI_POSITION , positions , { expires: 10 });
                }
            });
         });​
    

    HTML:

    <ul id="sortable"> 
      <li id="id_1"> Item 1 </li> 
      <li id="id_2"> Item 2 </li> 
      <li id="id_3"> Item 3 </li> 
      <li id="id_4"> Item 4 </li> 
      <li id="id_5"> Item 5 </li> 
    </ul>
    

    PHP:

    this is just an example but you got the idea: you may want use a database instead and use AJAX for get back the lis:

    <?php  
    //check if cookie is set..
    if ( isset( $_COOKIE['li_position'] ) ) {
    //explode the cockie by ";"...
    $lis = explode( ';' , $_COOKIE['li_position'] );
    // loop for each "id_#=#" ...
    foreach ( $lis as $key => $val ) {
    //explode each value found by "="...
    $pos = explode( '=' , $val );
    //format the result into li...
    $li .= '<li id="'.$pos[0].'" >'.$pos[1].'</li>';
    }
    //display it
    echo $li;
    // use this for delete the cookie!
    // setcookie( 'li_position' , null );
    } else {
    // no cookie available display default set of lis
     echo '
      <li id="id_1"> Fuji </li> 
      <li id="id_2"> Golden </li> 
      <li id="id_3"> Gala </li> 
      <li id="id_4"> William </li> 
      <li id="id_5"> Jordan </li> 
    ';
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There is an interesting article here on maintaing backwards compatibility for Java. In the
I'm having an interesting but difficult problem with my JavaScript code. Basically, I'm trying
Any idea how the youtube video uploader works? The interesting feature here is that
I've got pretty interesting question about EcmaScript-5 Function.prototype.bind implementation. Usually when you use bind,
Here is an interesting one... I have an application I am writing for devices
Here's an interesting writeup of using eye tracking software to generate heat maps that
Here's an interesting problem to solve in minimal amounts of code. I expect the
Interesting one here. I have an ASP.NET 1.1 project that contains a web service
I have an interesting problem here I've been trying to solve for the last
I have a problem with Menu button on Android 4.0. Here's the interesting part

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.