how to find the position of coordinate on clicked position ?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
PHPycho
Forum Contributor
Posts: 336
Joined: Fri Jan 06, 2006 12:37 pm

how to find the position of coordinate on clicked position ?

Post by PHPycho »

hello forums!!
I am wondering to know -
how to find the position of coordinate on clicked position ? using javascript.

Case:
Suppose i had a image ,when mouse is clicked @ certain position of image, then it should alert the x & y coordinate of that point..

Awaiting for your great help..
Thanks in advance to all of you
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Post by califdon »

Could you use image slices and an imagemap? Check out: http://www.ihip.com/
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

could use an <input type="image"/> to submit to the server. It reports the x & y of where you clicked the image in the GET/POST request. unfortunately, there's no javascript interface I know of.

Maybe you could embed it in a form with an onsubmit handler that intercepts the POST and cancels it? Not sure if it would work... but it's worth investigating!
mandar-seo
Forum Newbie
Posts: 6
Joined: Mon Jun 19, 2006 11:59 pm
Location: pune, india

Post by mandar-seo »

I think Keiren's advice should work. That seems logical. Creating image will not give you precise location of x and y. Try a bit and you will get it.

With regards,
Mandar Thosar
User avatar
PHPycho
Forum Contributor
Posts: 336
Joined: Fri Jan 06, 2006 12:37 pm

Post by PHPycho »

knock knock !!
but the clicked coordinates for the same position are different for different resolutions..How to avoid such problems...
thanks in advance to all of you
Awaiting for the valueable help
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

From what I understand the image button only send click coordinates in IE (though I could be wrong).

I did find this little gem whilst asking my good buddy Google if he knew anything about 'Javascript capture click coordinates'. I am wondeing if that could be useful to you.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Say what? There are like, a dozen attributes of a mouse click... Somewhere along the line, the math should be able to give you the correct coordinates. It's just.. a lot of trial and error (for me). clientX, clientY, scrollX, scrollY, scrollLeft, scrollTop, layerX, layerY, and a bunch of other ones. Match them up with the image's position, and you should be able to come up with the correct coordinates.... Or, am I misinterpreting the topic?
Post Reply