I have this script that determines the position of an element (x position, y position), I am trying to use ajax to send it to this update.php file and update the table.
this.addEventListener("load", doSomething, true);
function doSomething(e) {
var myElement = document.querySelector("#myElement");
var position = getPosition(myElement);
alert("The image is located at: " + position.x + ", " + position.y);
}
function getPosition(element) {
var xPosition = 0;
var yPosition = 0;
while(element) {
xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
element = element.offsetParent;
}
return {
x: xPosition,
y: yPosition
};
}
This gives me a nice alert with position, but just need it so in update.php I can retrieve it easily like $_POST['x']
and $_POST['y']
.