"TheKeith" <no@spam.com> writes:
Can someone tell me why this isn't working?
function getcoords() {
document.getElementById("coord-x").value = event.clientX + "";
You expect "event" to be a global value. That is an IE-specific
assumption, and it fails in most other browsers.
Solution: let "event" be an argument to the function.
You don't need the +"". Anything assigned to an input elements
value is automatically converted to a string.
<a href="#" onClick="getcoords();">Click here</a>
You forget to return false from the onclick handler, so after the
getcoords function has run, the page is reloaded (with an "#" at the
end of the address).
Change to:
<a href="" onclick="getcoords(event);return false">Click here</a>
(also passes event as argument to function. The event is available
inside the code of HTML event-handler attributes as the variable
"event", so it is ok to write "event" here).
Isn't event.clientX and clientY supposed to return an integer value?
They are supposed to *be* integer values.
Functions return, values are.
If so, why isn't this working?
"Not working" is close to useless as an error report. When asking for
help, you get the best response if you say:
1) What you do (code, what to click, etc, so we can try to recreate
the problem).
2) What is supposed to happen (hard to guess since it doesn't)
3) What really happens for you (maybe we can't recreate the problem)
In your case, the code works perfectly. Then the page is reloaded.
/L
--
Lasse Reichstein Nielsen -
lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'