473,662 Members | 2,524 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to use event.clientX and clientY

Can someone tell me why this isn't working?

<html>
<head>
<title>Untitl ed Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function getcoords() {
document.getEle mentById("coord-x").value = event.clientX + "";
document.getEle mentById("coord-y").value = event.clientY + "";
}
</script>
</head>
<body>
<input id="coord-x" type="text">
<input id="coord-y" type="text">
<a href="#" onClick="getcoo rds();">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 21667
"TheKeith" <no@spam.com> wrote in message
news:R_******** ************@gi ganews.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*****@litote s.demon.co.uk> wrote in message
news:bo******** ***********@new s.demon.co.uk.. .
"TheKeith" <no@spam.com> wrote in message
news:R_******** ************@gi ganews.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.getEle mentById("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="getcoo rds();">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="getcoo rds(event);retu rn 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/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #4
"TheKeith" <no@spam.com> wrote in message
news:aZ******** ************@gi ganews.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
2729
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
9781
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
2530
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 now convinced that this is the issue. In the code posted below, I am attempting to demonstrate the problem. If you load the code below into IE (the behavior is the same in Firefox, but the example code is IE specific), then click the first...
5
3048
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 reasonable? The script is here: http://www.lunds.us/private/coolclock.htm
5
5198
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 positioning a javascript routine, but I'm having trouble. When the javascript routine comes up, it comes up in a certain position based on window.event.clientX. However, the user could click on something in the script display (say, like a menu, or a...
6
14386
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 undefined.
1
2530
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 is change when position on particular part of control. But the function being called by my onmousedown event has error telling me a syntax error on line 90 (mouseDragImage). What is wrong with it? Thanks in advance. den2005 function...
5
4530
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 onmouseleave / onmouseout event I've attached to my hidden drop down (in this case an <ul>), is not firing correctly. It seems that when the mouse enters the ul it fires the mouseleave event. The problem is in the hideMenu2(e) function. I'm copying...
5
34361
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 helps to recognise whether the close button is clicked( also differentiates whethet refresh was clicked). The problem arises whenever i try to close the window by resizing it or by right clicking at the bottom of the page and then closing it. Can...
0
8857
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8546
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8633
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6186
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5654
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4347
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2762
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1993
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.