/    Sign up×
Community /Pin to ProfileBookmark

Control Mouse click position on the image

How to control the mouse click position on the image? That means i want the mouse click is when 5 times clicked, it will stop and pop up message indicated user has already click 5 times.

After that, how to post the click times value to the server side scripting i.e php?

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@iokosanFeb 22.2009 — <i>
</i>&lt;html&gt;
&lt;body&gt;
&lt;script&gt;
function trova(event){
img = document.getElementById("im")
document.getElementById("asc").value = (document.all)?event.offsetX:event.pageX-img.offsetLeft;
document.getElementById("ord").value = (document.all)?event.offsetY:event.pageY-img.offsetTop;

}
&lt;/script&gt;

&lt;img src="test.jpg" onclick="trova(event);" id="im"/&gt;
&lt;br/&gt;
&lt;input type="text" id="asc"/&gt;
&lt;br/&gt;
&lt;input type="text" id="ord"/&gt;
&lt;/body&gt;
&lt;/html&gt;


this way you can find mouse coords when an image is clicked. the "5 times" limit may be implemented creating a global variable incremented by 1 each time, and, when the 5th click occours, execute a xmlhttprequest.
Copy linkTweet thisAlerts:
@wterauthorFeb 22.2009 — How to execute a xmlhttprequest? Can u explain?
Copy linkTweet thisAlerts:
@iokosanFeb 22.2009 — http://www.w3.org/TR/XMLHttpRequest/

google and the search button are your best friends
Copy linkTweet thisAlerts:
@wterauthorFeb 22.2009 — Is it possible that the click is in the sequence of clicked i.e form 1st click ..... to 5th clicked? And that sequence can be save to database?
×

Success!

Help @wter spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...