PDA

View Full Version : JS Help with capturing XY of mouse at certain points, please help!


james.lat
03-16-2010, 09:13 PM
Hey All-
I need some help capturing the points of the mouse at certain times using JS.
i know how to find the current X,Y of the mouse using JS (i'll include code at the end)
what i need to do is find out the x,y of the mouse whenever the user clicks on the page. then as the user holds down and moves the mouse he/she will create an invisible box, and whenever they let up from the mouse i want to recore that x,y and as well.
How can i do this With JS
(here is my working code to find the X,Y of wherever the mouse is)
Thanks a lot!
-James

<form name="Show">
<input type="text" name="MouseX" value="0" size="4"> X<br>
<input type="text" name="MouseY" value="0" size="4"> Y<br>
</form>

<script language="JavaScript1.2">
<!--
var IE = document.all?true:false
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
var tempX = 0
var tempY = 0
function getMouseXY(e) {
if (IE) {
tempX = event.clientX + document.body.scrollLeft
tempY = event.clientY + document.body.scrollTop
} else {
tempX = e.pageX
tempY = e.pageY
}
if (tempX < 0){tempX = 0}
if (tempY < 0){tempY = 0}
document.Show.MouseX.value = tempX
document.Show.MouseY.value = tempY
return true
}

//-->
</script>