Solved

jquery draggable

Posted on 2014-09-08
2
315 Views
Last Modified: 2014-09-08
Hi, I am very close to solving this just need a little push. I have a script that I am writting that allows you to drag an image. When you let go I want to send the position to data.php that will then record it. In firebug I used console.log and can see the x and y but when I pass the data I get object object.

Here is my jquery (it has php mixed in)
<script>

$(function() {
$( "#draggable<?=$x;?>" ).draggable({
        snap: true,

        drag:
                function(event,ui) {
                        theUserPos<?=$x;?> = ui.position;
                        console.log(theUserPos<?=$x;?>);
                },

        stop:
                function ( event, ui ) {
                        alert(theUserPos<?=$x;?>);
                        // parameters will be a string "id[]=1&id[]=3&id[]=10"...etc
                        //$("#info").load("update.php?"+theUserPos<?=$x;?>);





                        // send new sort data to process
                        $.ajax("data.php?"+theUserPos<?=$x;?>);
                }


        });

});
</script>

Open in new window


URL: http://rack.customphpdesign.com/index.php?action=new_rack&type=1/3
0
Comment
Question by:Robert Saylor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 40311120
Because ui.position is an array of the top and left values, to get either one use

ui.position.top
ui.position.left
0
 
LVL 7

Author Closing Comment

by:Robert Saylor
ID: 40311129
Thanks Gary that worked! I tried to follow the docs :)
0

Featured Post

Turn Insights Into Action

You’ve already invested in ITSM tools, chat applications, automation utilities, and more. Fortify these solutions with intelligent communications so you can drive business processes forward.

With xMatters, you'll never miss a beat.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question