Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Programming (http://www.go4expert.com/forums/programming-forum/)
-   -   Coordinates of a draggable object (http://www.go4expert.com/forums/coordinates-draggable-object-t20302/)

rwwilcox 7Dec2009 17:55

Coordinates of a draggable object
 
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:

shabbir 7Dec2009 18:17

Re: Coordinates of a draggable object
 
All you are trying to do is store some numbers in a file and what makes you think it cannot be done.

rwwilcox 7Dec2009 21:34

Re: Coordinates of a draggable object
 
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

venami 8Dec2009 00:03

Re: Coordinates of a draggable object
 
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;


tommyp 9Dec2009 22:37

Re: Coordinates of a draggable object
 
This is quite usefull, how would one submit this into a form textarea when the form is submitted?

venami 9Dec2009 23:01

Re: Coordinates of a draggable object
 
Create a javascript which takes the above two values as arguments. Inside the function, use:
Code:

// here 'txtarea' inside brackets is the ID set for the textarea tag
txtarea = document.getElementbyId('txtarea');
txtarea.value = x + " " + y;

Then in the onlcick event of the submit button, call this function.


All times are GMT +5.5. The time now is 10:03.