Click to See Complete Forum and Search --> : Finding Mouse Coordinates


code?
November 4th, 2006, 08:15 PM
I know how you find mouse coordinates, but when I loop it, it doesn't work.

<script>
function UpdateMouse()
{
var X = event.clientX;
var Y = event.clientY;
Status.innerText = "(" + X + "," + Y + ")";
setTimeout("UpdateMouse()",100);
}
</script>
<body onload="UpdateMouse();">
<center id="Status></center>

It does it once, but then it says:

Error: Object Required

PeejAvery
November 4th, 2006, 08:30 PM
You are calling an event, but no event exists. Use the following.

<script language="JavaScript">
var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = mousecoords;
function mousecoords(e){
if(document.all){
xpos = event.clientX + document.body.scrollLeft;
ypos = event.clientY + document.body.scrollTop;
}
else{
xpos = e.pageX;
ypos = e.pageY;
}
if(xpos < 0){xpos = 0;}
if(ypos < 0){ypos = 0;}

document.getElementById('xcoord').value = xpos;
document.getElementById('ycoord').value = ypos;
}
</script>

X: <input type="text" id="xcoord">
Y: <input type="text" id="ycoord">