Lenny Magico
Lenny Magico

Reputation: 1203

PHP get div position and store in session

I know how to get the position of a div using JS, I'm using Jquery's draggable script, and have an event that when the person stop dragging that it should get the location of the div (top and left):

document.getElementById('object').style.top;
document.getElementById('object').style.left;

now the question is how do I get those coordinates into a php session...?

Upvotes: 1

Views: 1976

Answers (3)

Lenny Magico
Lenny Magico

Reputation: 1203

This is the final solution I made thanks to GolezTrol :), I never knew you could make cookies using js

    <script type="text/javascript">
        function setCookie(c_name,value,exdays){
        var exdate=new Date();
        exdate.setDate(exdate.getDate() + exdays);
        var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
        document.cookie=c_name + "=" + c_value;
        }
    </script>
    <script type="text/javascript">
    $(function() {
        $( "#object" ).draggable({ containment: ".body", scroll: false });
        $( "#object" ).bind( "dragstop", function(event, ui) {
          var l = document.getElementById('object').style.left;
          javascript: setCookie('objectl', l, 365);
          var t = document.getElementById('object').style.top;
          javascript: setCookie('objectt', t, 365);
        });
    });
    </script>

Upvotes: 0

GolezTrol
GolezTrol

Reputation: 116110

Maybe the best (easiest) option is to store them in a cookie. The cookie can be read by PHP if you like, but even if you don't, you can still use the cookie again when the page is reloaded in the same browser.

If you want to store the value so it is kept too if the user logs in on another browser (or in a different session), you can store the cookie in a database.

Upvotes: 4

AndreKR
AndreKR

Reputation: 33678

On drop, make an Ajax request to a PHP script that puts them into $_SESSION.

Upvotes: 2

Related Questions