F
finerrecliner
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>
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>