Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting the mouse coordinates (X,Y), 1

Status
Not open for further replies.

perlTest

Programmer
Nov 16, 2002
14
0
0
US
I need some help solving a problem I've encountered.
I need to get the mouse coordinates (X,Y),
(I do it by calling a function with "onMouseMove" that takes an event parameter.

it looks like this:

<html>
<head>
<script language=&quot;JavaScript&quot;>
function show(event){

X = e.clientX;
Y = e.clientY;

alert(&quot;x=&quot;+x+&quot; y=&quot;+y);
}
</script>
</head>
<body onMouseMove=&quot;show(e);&quot;>
</body>
</html>

(This is a symplified code).
The problem is, that all of those event handlers dealing with the mouse coordinates (event.x, event.clientX, event.offsetX) deal with the location of the mouse relativitly to the SCREEN and not the HTML PAGE.
I need a code or a new methos that will allow me to get the X,Y coordnates according to the Page.
(If you didn't understand something -And you know how to program in JavaScript-, please tell me so I could clearify).

Does anybody have any idea on how to solve this important issue? Thank You.
 
this gives it according to the page, when you go to the top left corner of the page it gives x=0 and y=0, and thats correct.
Code:
<html>
<head>
<script language=&quot;JavaScript&quot;>
function show(e){

x = e.clientX;
y = e.clientY;

alert(&quot;x=&quot;+x+&quot; y=&quot;+y);
}
</script>
</head>
<body onMouseMove=&quot;show(event);&quot;>
</body>
</html>
hope it helps &quot;Those who dare to fail miserably can achieve greatly.&quot; - Robert F. Kennedy
So true..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top