D
Dave H
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
button, you will see that the coordinates displayed are 0,0. As you
continue down the button list, you will see that each subsequent button
click displays the previous button coordinates.
This behavior clearly demonstrates that the input element onClick
handler is executed before the document.onclick handler.
In order to be able to capture the coordinates of the button currently
being pressed, the event handlers would have to execute in the opposite
order.
My question: is there any way for me to specify the order in which the
onclick handlers execute? If not, is there some other way I can code
this to produce the desired result?
---- code below here ----
<HEAD>
<SCRIPT LANGUAGE="javascript">
document.onclick = saveCursorPos;
cursorX = 0;
cursorY = 0;
function saveCursorPos(e) {
var ev = window.event;
cursorX = ev.clientX;
cursorY = ev.clientY;
document.forms[0].cp.value = cursorY + ',' + cursorX;
}
function clickme () {
alert('Y='+cursorY+',X='+cursorX);
}
</SCRIPT>
</HEAD>
<BODY>
<FORM>
<INPUT TYPE=TEXT NAME="cp" VALUE=""><BR>
<INPUT TYPE=BUTTON VALUE="clickme" onClick="javascript:clickme();"><BR>
<INPUT TYPE=BUTTON VALUE="clickme" onClick="javascript:clickme();"><BR>
<INPUT TYPE=BUTTON VALUE="clickme" onClick="javascript:clickme();"><BR>
<INPUT TYPE=BUTTON VALUE="clickme" onClick="javascript:clickme();"><BR>
</FORM>
</BODY>
---- end of code ----
Thanks,
Dave H.
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
button, you will see that the coordinates displayed are 0,0. As you
continue down the button list, you will see that each subsequent button
click displays the previous button coordinates.
This behavior clearly demonstrates that the input element onClick
handler is executed before the document.onclick handler.
In order to be able to capture the coordinates of the button currently
being pressed, the event handlers would have to execute in the opposite
order.
My question: is there any way for me to specify the order in which the
onclick handlers execute? If not, is there some other way I can code
this to produce the desired result?
---- code below here ----
<HEAD>
<SCRIPT LANGUAGE="javascript">
document.onclick = saveCursorPos;
cursorX = 0;
cursorY = 0;
function saveCursorPos(e) {
var ev = window.event;
cursorX = ev.clientX;
cursorY = ev.clientY;
document.forms[0].cp.value = cursorY + ',' + cursorX;
}
function clickme () {
alert('Y='+cursorY+',X='+cursorX);
}
</SCRIPT>
</HEAD>
<BODY>
<FORM>
<INPUT TYPE=TEXT NAME="cp" VALUE=""><BR>
<INPUT TYPE=BUTTON VALUE="clickme" onClick="javascript:clickme();"><BR>
<INPUT TYPE=BUTTON VALUE="clickme" onClick="javascript:clickme();"><BR>
<INPUT TYPE=BUTTON VALUE="clickme" onClick="javascript:clickme();"><BR>
<INPUT TYPE=BUTTON VALUE="clickme" onClick="javascript:clickme();"><BR>
</FORM>
</BODY>
---- end of code ----
Thanks,
Dave H.