0

Got a nice solution for my project on stack but I test now some days for a solution to save data after switch in db.

The original post: change switch position behavior

$(function() 
{
    $(".swapable").
        draggable({ revert: true }).
        droppable(
        {
            drop:function(event,ui)
            {
                swapNodes($(this).get(0),$(ui.draggable).get(0));
            }
        });
});

function swapNodes(a, b) 
{
    var aparent= a.parentNode;
    var asibling= a.nextSibling===b? a : a.nextSibling;
    b.parentNode.insertBefore(a, b);
    aparent.insertBefore(b, asibling);
}

http://jsfiddle.net/keGuN/1/

Now I want use the stop to save something after drop.

$(function() {
    $(".swapable").
        draggable(
        { 
            revert: true,
            stop:function()
            {
                // put new div combination in db
            }
        }).
        droppable(
        {
            drop:function(event,ui)
            {
                swapNodes($(this).get(0),$(ui.draggable).get(0));
            }
        });
});

function swapNodes(a, b) 
{
    var aparent= a.parentNode;
    var asibling= a.nextSibling===b? a : a.nextSibling;
    b.parentNode.insertBefore(a, b);
    aparent.insertBefore(b, asibling);
}

How to find a way to put new div combination put in database?

My problem is how to get the right way to show new div combination.

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • Hey, how far are you getting? What have you tried? What are the errors that you're encountering? – msturdy Nov 18 '13 at 18:08
  • btw im a newbie. Hi i want to use sortable but i didnt found something to change object position "a" with object "b". sortable changes the positions if the (mouse)hold item pass the way. with this code above i cant use sortable methods serialze :-( i got a big list with divs with an uniquer id for each div. all the divs are in one big div. the normal position is 1-100 like
    1
    2
    ...
    if position changes i use on stop html() to an var with alert. the alert shows me all the html code. i cant use it. i think need an array but
    – Chris M. Nov 18 '13 at 18:36
  • dont understand how it works. if the array is done i want to save the new div position list in my db – Chris M. Nov 18 '13 at 18:40
  • oh this works var some = []; $('div#boxcreator div').each(function () { some.push($(this).attr("id")); }); alert(some); – Chris M. Nov 18 '13 at 18:48
  • Ok, so think about what you need to do this. The JS in the browser doesn't have access to your DB directly, so you'll need a script on your server to receive the new order, and update the DB. Now think about the data format that your AJAX script will need to be able to recognise and reorder the items in your DB. Then send the AJAX request to your script, process it into the DB, then anticipate the response from the server in the JS on the page.. – msturdy Nov 18 '13 at 18:58

0 Answers0