Click to See Complete Forum and Search --> : if (!event.clientX) does not work. why?


michelle
08-25-2003, 07:28 AM
I have a function that sometimes gets called from another function and sometimes directly from a link.

To detirmine whether the mouse was clicked or it was called from the function, I have this code, but it only works if I click a link.
I ask myself, why?

function changeLeft(uid) {
if (!event.clientX) {
document.getElementById(uid).style.left = "100";
} else {
document.getElementById(uid).style.left = event.clientX;
}
}

Any thoughts?
// Michelle

pyro
08-25-2003, 07:53 AM
This should work better...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Mouse Position</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script type="text/javascript">
function changeLeft(uid, event) {
if (!event) {
document.getElementById(uid).style.left = "100px";
}
else {
document.getElementById(uid).style.left = event.clientX;
}
}
function changePos() {
changeLeft('mydiv');
}
</script>

</head>
<body>
<p><a href="#" onclick="changePos(); return false;">Function to change</a></p>
<p><a href="#" onclick="changeLeft('mydiv', event); return false;">changeLeft</a></p>
<div id="mydiv" style="position: absolute; border: 1px solid; width: 30px">test</div>
</body>
</html>