473,383 Members | 1,818 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

How to use event.clientX and clientY

Can someone tell me why this isn't working?

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function getcoords() {
document.getElementById("coord-x").value = event.clientX + "";
document.getElementById("coord-y").value = event.clientY + "";
}
</script>
</head>
<body>
<input id="coord-x" type="text">
<input id="coord-y" type="text">
<a href="#" onClick="getcoords();">Click here</a>
</body>
</html>

Isn't event.clientX and clientY supposed to return an integer value? If so,
why isn't this working? Thanks.
Jul 20 '05 #1
4 21632
"TheKeith" <no@spam.com> wrote in message
news:R_********************@giganews.com...
Can someone tell me why this isn't working?
<snip>
Isn't event.clientX and clientY supposed to return an
integer value? If so, why isn't this working? Thanks.


How are you defining "isn't working" in this context? As this (almost)
IE only code is doing exactly what it is being asked to do in IE 6.

Richard.
Jul 20 '05 #2

"Richard Cornford" <Ri*****@litotes.demon.co.uk> wrote in message
news:bo*******************@news.demon.co.uk...
"TheKeith" <no@spam.com> wrote in message
news:R_********************@giganews.com...
Can someone tell me why this isn't working?

<snip>

Isn't event.clientX and clientY supposed to return an
integer value? If so, why isn't this working? Thanks.


How are you defining "isn't working" in this context? As this (almost)
IE only code is doing exactly what it is being asked to do in IE 6.

Richard.

Well, I expect it to write the x position and y position of the pointer, at
the time of my clicking the link, to the text fields. Why is this an almost
only ie code? thanks.
Jul 20 '05 #3
"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.'
Jul 20 '05 #4
"TheKeith" <no@spam.com> wrote in message
news:aZ********************@giganews.com...
<snip>
How are you defining "isn't working" in this context? As this
(almost) IE only code is doing exactly what it is being asked
to do in IE 6.
<snip>Well, I expect it to write the x position and y position of the
pointer, at the time of my clicking the link, to the text fields.
And that is exactly what it does on my IE 6 (with the caveat that the X
and Y coordinates are relative to the upper left corner of the inner
border of the client area).
Why is this an almost only ie code? thanks.


The function called by the event handling code uses the global
identifier "event" and originally only IE browsers supported a global
event object, more recently, in a bid for compatibility with IE, some
other browsers have implemented global event objects, but not all.

Richard.
Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Marcia Gulesian | last post by:
How can I capture the event when I click (focus) with the cursor anywhere in the page (that is, on a component or elsewhere). This event would occur in an I.E 5.5 or later browser.
10
by: Tom Szabo | last post by:
Is there an event when that triggers when the window is closing.... I am talking about when the user clicks on the cross on the right top corner of the window!!!
4
by: Dave H | last post by:
I originally posted a message "Getting the current cursor position using clientX,clientY" in which I hypothesised that the problem I was having was related to event handler execution order. I am...
5
by: code_wrong | last post by:
Hi Firefox does not support the IE specific 'event' identifier and just quits running the script. ..... even though the identifier only turns up in code marked for IE only ... Does this seem...
5
by: chad.a.morris | last post by:
Hi everyone, I didn't know how to sum this up very well for the title, but hopefully the person(s) will come along who can help. I'm trying to use the window.event.clientX value for...
6
by: RC | last post by:
I am try to detect the mouse pointer by var event = window.event; var x = event.pageX; var y = event.pageY; This is working fine in IE, but in Netscape/Firefox where event return...
1
by: den2005 | last post by:
Hi everybody, I am new in javascript. I am working on resizing a control like Image by dragging it to a desired size at runtime. Now, my onmouseover event is working ok where the cursor type...
5
by: jaysonnward | last post by:
Hello All: I've recently been recreating some 'dropdown menus' for a website I manage. I'm writing all my event handlers into my .js file. I've got the coding to work in Firefox, but the...
5
by: jimmy | last post by:
Hi all, I want to capture the event when the browser's close button is clicked in an html page. I tried using the event.ClientX and event.ClientY property in the body unload event, and this...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.