Page 1 of 1

Getting click co-ordinates without using image input

Posted: Wed Jun 20, 2012 10:48 am
by dave1909
How can i find the position of a submit button that is clicked without using input type="image"

Is there any way of doing this without Jquery? It seems like overkill.

I dont want to use input type="image" because i've styled all my input buttons.

Is there any way to get 'submit_x' and 'submit_y' any other way? Thanks

Re: Getting click co-ordinates without using image input

Posted: Wed Jun 20, 2012 11:26 am
by twinedev
Well technically, you can do it with plain javascript, which isn't using jQuery ;-)

I think the more important thing to ask though is what are you trying to accomplish, do you have multiple submit buttons and want to know which one they clicked on? or specifically where on a single button you are clicking?

Re: Getting click co-ordinates without using image input

Posted: Wed Jun 20, 2012 11:37 am
by dave1909
It's part of a browser based game, somebody suggested to me this as a way of detecting auto clickers.

I'm already using a javascript function to set hidden values in the form when a user clicks the button to prevent people using refreshing scripts.

How would i go about doing this in plain javascript then?

Re: Getting click co-ordinates without using image input

Posted: Wed Jun 20, 2012 3:13 pm
by pickle
I think you could add an onclick event listener to the body. Inside that event object should be the coordinates of the click.