h1

jQuery Drag And Drop Sample

December 2, 2008

I was playing with jQuery today and was able to create a simple demonstration of its draggable/droppable function. Most know this as “Drag and Drop” functionality.

Just wanna share with you what i just made. The sample i made counts all the items and the total of each item dragged to the drop zone. It would pop an alert when the drop zone is already full. So far, I have tested this in Firefox and IE 6 and works fine.

this is the header script:

Drag and Drop code

this is the body script:

Drag and Drop Code

Here is the screenshot:

jQuery drag and drop Screenshot

You can download the zip file here: Drag and drop.zip

HTH :)

32 comments

  1. A Univeral Builder for Drag and Drops (free, based in jQuery):
    http://mynichecomputing.org/GuideInfoandPlanner/UniversalDD.htm


  2. nice post.. :)

    can u made some like this with connection to mysql !!


  3. sure, that’s a great idea :) thanks


  4. nice tutorial, better than ui droppable tutorial at jquery official site


  5. @kalong,

    thanks for dropping by :)

    jhoy


  6. dude.. attached sources are not working with ie7,however working with Mozilla…but i desperately searching for ie support.can you help me in resolving problem


  7. @prasad,

    hi! i re-tested the files and it is working in my IE6.

    jhoy


  8. Thanks for Quick Response dude..

    its not working in IE7.


  9. hi,

    lemme install IE7 first :D


  10. ok…Thnks for your time…

    –Prasad.


  11. hi prasad,

    i just tested it in IE7 and it is working fine. what seems to be the problem?

    jhoy


  12. i couldnt able to drag and drop the items


  13. how to restrict the item to drag and drop not more than one time.


  14. just change this part

    “if(itemTotalCtr >= 10)” to “if(itemTotalCtr >= 1)”

    HTH


  15. thanks, but i want each item to be drag only once.
    for example, if dropped dog, then again i should not dropped dog in the box.


  16. i see. we need tweak the code for that. ill try to modify it and send it to you but it would be after a couple of hours coz im busy right now. will that be okay?


  17. Hey,

    scvinodkumar : i want each item to be drag only once.
    for example, if dropped dog, then again i should not dropped dog in the box.

    once you have dropped dog in the droppend box,you jus apply remove ui-draggable feature on that dropped item,it will remove out the draggable feature of item.
    for example : item.removeClass(“ui-draggable”)

    above i have given small tip,please let me know in case of any issues,

    Prasad.


  18. yeah thanks very much


  19. hi, i have added some code for this

    var itemArray = new Array();

    if(jQuery.inArray(dropElemId, itemArray)==-1)
    itemArray.push(dropElemId);
    else
    {
    alert(‘You have already moved this item’);
    return;
    }


  20. very nice! did it worked as you wished?


  21. Yeah! thanks for this great plugin


  22. you’re welcome! glad it helped :D


  23. Hi jhoy imperial, also could you tell me how to delete the items that are dropped into the box


  24. sorry, but i haven’t tried that though.


  25. ok, let me try. can i have ur mail id


  26. Hi jhoy imperial,

    I updated the latest version of jquery, but it is not droppable. Could you please check it. since i am using with jcarousel


  27. sure! what should be its functionality?


  28. Hi jhoy,

    Its a neat example!

    -Wali.


  29. Hi there, very nice tutorial.
    Thank you.


  30. thank you :)


  31. hi,
    thanks for ur code but where are the css for that


  32. Hello Jhoy,

    Is there any way to implement two way drag and drop..? Mean I should be able to do normal drag-drop, also the dropped items should be draggable, so I can drag those to another droppable region.

    I have multiple area on the page, all areas are droppable and draggable, so how it could be implemented in such a way that.. everything works?

    Thanks,
    Sajal



Leave a Comment