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

  • Home
  • SEARCH
  • 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 9203897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:34:32+00:00 2026-06-17T23:34:32+00:00

I am having an issue trying to get an array out of JS using

  • 0

I am having an issue trying to get an array out of JS using the sortable on some drag and drop elements.
A working demo can be found at:

Example

What I need to achieve:

  1. Drag item on image, get x,y (done)
  2. after all items have been placed, use jQuery sortable? to get array of id’s with x,y coordinates.

array(23456->{xpos:234,ypos:234},23456->{xpos:234,ypos:234},….etc

I am not sure how to bind the sortable to the items only dropped on the image, and then get those values into an array

Here is the code so far:

jQuery(function($){

$('.dragThis').bind('click', function(){
        $(this).css("border","3px solid #fff");

        $(this).draggable({
                            containment: $('body'),
                            drag: function(){
                                    $('#dropHere').droppable({
                                        accept: '.dragThis',
                                        over : function(){
                                        $(this).animate({'border-width' : '3px', 'border-color' : '#0f0'}, 500);

                                        }
                                    });

                                },
                            stop: function(){

                                    var position = $(this).position();
                                    var parentPos = $('#dropHere').offset();
                                    var xPos = position.left - parentPos.left;
                                    var yPos = position.top - parentPos.top;
                                    var finalOffset = $(this).position();
                                    var finalxPos = xPos;
                                    var finalyPos = yPos;
                                    $('#finalX').text('Final X: ' + finalxPos);
                                    $('#finalY').text('Final Y: ' + finalyPos);
                                    //$('.dragThis').sortable();
                                    console.log (finalxPos,finalyPos,$(this).attr("id"));
                                },
                            revert: 'invalid'
                            //connectToSortable: '#dropHere'
        });

    });

});

Any help getting pointed in the right direction, is greatly appreciated.
Just to clarify, I will be writing the values via AJAX to a DB for recall later.

Thanks in advance

  • 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-06-17T23:34:34+00:00Added an answer on June 17, 2026 at 11:34 pm

    Simple solution:

    1. Add a class for those elements on their own ‘drop’ event, then get all of those have classes with a selector.

    2. After that, a handy $.fn.each() and $.fn.offset() will help.

    3. You can then work on those coordinates with top, left instead of your mentioned xpos, ypos.

    Here is an example:

    var coordinates = {};
    
    $(".dropped").each(function(item) {
        coordinates[$(item).attr("id")] = $(item).offset();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get data out of a list,but facing some issue while
The issue I'm having is issue with is I'm trying to get the paintComponent
I'm having an issue here, I am trying to get all the titles from
I'm trying to get the Mailchimp datasource from Springest working, and I'm having issues.
I am trying to get php's namespace technique down but having some issues here:
I'm trying to get started with twitter4r but I'm having some issues: Why I
I am having an issue trying to get my affiliate tracking pixels to mark
I'm trying to get full text search working in Yii and I can't seem
I've been having some issues trying to use cURL and JSON to print out
I am having an issue trying to post a JSON string using dojo.xhrPost to

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.