Darkness Posted August 5, 2009 Share Posted August 5, 2009 This code finds the X and Y coordinates of a click: function find_coorddinates(e){FC_CurrentX= 0;FC_CurrentY= 0;if(!e){e= window.event;}if(e.pageX || e.pageY){FC_CurrentX= e.pageX;FC_CurrentY= e.pageY;}else if(e.clientX || e.clientY){FC_CurrentX= e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;FC_CurrentY= e.clientY + document.body.scrollTop + document.documentElement.scrollTop;}window.ReturnX= parseFloat(FC_CurrentX);window.ReturnY= parseFloat(FC_CurrentY);} On the page, I have this: window.onclick= find_coordinates; Normally it works.. however, if one clicks on a submit field, it does not appear to work: <input type='submit' value='Submit' class='submit' onclick=\"this.disabled= true; this.value='Loading...'; submit_field();\"> In other words, it does not change window.ReturnX and window.ReturnY which are the variables that hold the X/Y co-ordinates. However, if I click anywhere else randomly, it works. Link to comment Share on other sites More sharing options...
jeffman Posted August 5, 2009 Share Posted August 5, 2009 Are you sure? Events bubble upward. If you're trying to evaluate window.ReturnX inside your submit_field() function, it will not have been changed yet, because the button's click handler fires first; the window's click handler fires afterward.If you're evaluating window.ReturnX in some other way that you haven't mentioned, the change might not be obvious, since the form is being submitted, and a new page loaded (or the same page reloaded). Keep in mind: while you're handling these events, a submit event is also occurring. That's two events and two objects you're trying to keep track of. If you're updating the display in the middle of all that, it may happen too quickly to see.I'd suggest more, but without knowing more about your page, I'd just be guessing.I'm usually grateful when people don't post a big enormous page to resolve a teeny problem, but in this case you left out too much. Link to comment Share on other sites More sharing options...
Darkness Posted August 5, 2009 Author Share Posted August 5, 2009 Thanks for replying.Anyway, the problem is that the function which finds the coordinates never seems to fire afterward - I have attempted to use an alert() in the coordinate-finding function, the alteration of a span, etc. Never seems to fire when the button is clicked (the form is never submitted by the way - it fires an AJAX function). Link to comment Share on other sites More sharing options...
jeffman Posted August 5, 2009 Share Posted August 5, 2009 the form is never submitted by the way - it fires an AJAX functionAre you certain the form doesn't submit? I believe you're firing an AJAX function, but that doesn't mean the form isn't submitting also. To keep a form from submitting, you need to capture the click event or the submit event, and I don't see anything that does that. For all I know, you have something that does that. I don't know, because you're still discussing your code without posting it.Maybe someone else can help you. Link to comment Share on other sites More sharing options...
dsonesuk Posted August 5, 2009 Share Posted August 5, 2009 function find_coorddinates(e) ??? window.onclick= find_coordinates;for what i had to work with, i came up with this.<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Untitled Document</title><style type="text/css">body, html {height: 100%;}</style><script type="text/javascript">/*<![CDATA[*//*---->*/function find_coordinates(e){FC_CurrentX= 0;FC_CurrentY= 0;if(e ==undefined)e= window.event;if(e.pageX || e.pageY){FC_CurrentX= e.pageX;FC_CurrentY= e.pageY;}else if(e.clientX || e.clientY){FC_CurrentX= e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;FC_CurrentY= e.clientY + document.body.scrollTop + document.documentElement.scrollTop;}window.ReturnX= parseFloat(FC_CurrentX);window.ReturnY= parseFloat(FC_CurrentY);document.getElementById("xcoord").innerHTML="X Coordinates: "+ window.ReturnX;document.getElementById("ycoord").innerHTML="Y Coordinates: "+ window.ReturnY;}function submit_field(){alert("bbooo")}/*--*//*]]>*/</script> </head><body onmousedown="find_coordinates(event)"><div id="ycoord"> </div><div id="xcoord"> </div><input type='submit' value='Submit' class='submit' onclick="this.disabled=true; this.value='Loading...'; submit_field();"><p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex.</p> </body></html> Link to comment Share on other sites More sharing options...
Darkness Posted August 5, 2009 Author Share Posted August 5, 2009 Thanks for the help.The spelling error you mentioned is not actually like that in the actual script, by the way. =PSo, anyway... by adding this instead of window.onclick= find_coordinates;, it worked: <body onmousedown='find_coordinates(event);'> Thanks. Link to comment Share on other sites More sharing options...
dsonesuk Posted August 6, 2009 Share Posted August 6, 2009 Plus for IE you require:<style type="text/css">body, html {height: 100%;}</style> as IE will only register a click it seems, if a click is made from the top to the bottom edge of content text.making body 100% expands the clickable area to bottom of page. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.