467,894 Members | 1,491 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,894 developers. It's quick & easy.

mouse coordinates undefined

trying to get the mouse coordinates to show up in an alert box. but all
i get is "undefined"
the script should work like:
click the button, then click anywhere on the page to show your current
x coord, then click again anywhere on the page to show current Y coord,
then go back to normal mouse behavior.

must work in firefox 1.5+
Thanks!
<html>
<head>
<script type="text/javascript">
var x = 0;
function click()
{
if(x == 0)
{
//stops anything from happening when you click the
button
x = 1;
}
else if(x == 1)
{
mouseX(document.onclick);
x = 2;
}
else if(x == 2)
{
mouseY(document.onclick);
x = 0;
document.onclick=null;
}
else { alert("wtf");}
}
function getcoords()
{
document.onclick=click;
}
function mouseX(evt)
{
var Xcoord = evt.pageX;
alert(Xcoord);
}
function mouseY(evt)
{
var Ycoord = evt.pageY;
alert(Ycoord);
}
</script>
</head>
<body>
<button onclick="getcoords();">click here</button>
</body>
</html>

Aug 15 '06 #1
  • viewed: 1815
Share:
1 Reply
fi***********@gmail.com schrieb:
function click()
{
if(x == 0)
{
//stops anything from happening when you click the
button
x = 1;
}
else if(x == 1)
{
mouseX(document.onclick);
x = 2;
}
else if(x == 2)
{
mouseY(document.onclick);
x = 0;
document.onclick=null;
}
else { alert("wtf");}
}

your "click"-function will get as (first) argument a
window-event-object. just forward this to your "mouseX" and
"mouseY"-function:
function click() {
....
mouseX(arguments[0]);
...
mouseY(arguments[0]);
....
}

Aug 16 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Danny | last post: by
3 posts views Thread by mitsura | last post: by
7 posts views Thread by RobKinney1 | last post: by
2 posts views Thread by quickcur | last post: by
3 posts views Thread by wanwan | last post: by
2 posts views Thread by romain.larmet | last post: by
4 posts views Thread by =?Utf-8?B?Unlhbg==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.