HighDots Forums  

Re: How to use event.clientX and clientY

Javascript JavaScript language (comp.lang.javascript)


Discuss Re: How to use event.clientX and clientY in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Lasse Reichstein Nielsen
 
Posts: n/a

Default Re: How to use event.clientX and clientY - 11-02-2003 , 11:09 PM






"TheKeith" <no (AT) spam (DOT) com> writes:

Quote:
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.

Quote:
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).

Quote:
Isn't event.clientX and clientY supposed to return an integer value?
They are supposed to *be* integer values.
Functions return, values are.

Quote:
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 - lrn (AT) hotpop (DOT) com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.