Coordinates of a draggable object

Discussion in 'Programming' started by rwwilcox, Dec 7, 2009.

  1. rwwilcox

    rwwilcox New Member

    Joined:
    Dec 7, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Does anyone know how to store the coordinates of a draggable image in a .txt file, to allow the same image to be re-loaded in the same position on another page?

    Hope someone can help,
    Thanks :pleased:
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    All you are trying to do is store some numbers in a file and what makes you think it cannot be done.
     
  3. rwwilcox

    rwwilcox New Member

    Joined:
    Dec 7, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    I know it can be done, and i know that i need to use GetElementById, e.clientX, and e.ClientY. But im new to this and just wanted some advice of how to go about it.

    Thanks
     
  4. venami

    venami New Member

    Joined:
    Dec 26, 2008
    Messages:
    195
    Likes Received:
    10
    Trophy Points:
    0
    Occupation:
    Software Professional
    Location:
    India, Tamil Nadu, Cuddalore
    Home Page:
    http://mvenkatapathy.wordpress.com
    But the clientx and clienty gives the current mouse position and not the image's position on a screen.
    You can do as follows:

    Code:
    var x = document.images.imagename.offsetLeft;
    var y = document.images.imagename.offsetTop;
    
     
  5. tommyp

    tommyp New Member

    Joined:
    Dec 9, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    This is quite usefull, how would one submit this into a form textarea when the form is submitted?
     
  6. venami

    venami New Member

    Joined:
    Dec 26, 2008
    Messages:
    195
    Likes Received:
    10
    Trophy Points:
    0
    Occupation:
    Software Professional
    Location:
    India, Tamil Nadu, Cuddalore
    Home Page:
    http://mvenkatapathy.wordpress.com
    Create a javascript which takes the above two values as arguments. Inside the function, use:
    Code:
    // here '[COLOR="Blue"]txtarea[/COLOR]' inside brackets is the ID set for the textarea tag
    txtarea = document.getElementbyId('[COLOR="blue"]txtarea[/COLOR]');
    txtarea.value = x + " " + y;
    
    Then in the onlcick event of the submit button, call this function.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice