Jump to content

Window.onclick And Submit


Darkness
 Share

Recommended Posts

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

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

Edited by Deirdre's Dad
Link to comment
Share on other sites

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

the form is never submitted by the way - it fires an AJAX function
Are 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. Edited by Deirdre's Dad
Link to comment
Share on other sites

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>

Edited by dsonesuk
Link to comment
Share on other sites

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...