team1504 — 2012-02-10T18:18:33-05:00 — #1
I have an idea for a script that I was hoping someone at the js forum could help me start or write a basic version of because i have no clue where to start it.
So what I am trying to accomplish is counting how many times a div (if necessary it can be a <button> or <input />) has been clicked and then displaying it. The counting meaning numbers of times clicked so that would have to be stored in a variable and then if the user clicks that number or variable is incremented by one.
Is this possible to do in js and if so can someone please help me start writing this ?
I would really appreciate any and all help with this
Thanks in Advance & Best Regards,
chris_upjohn — 2012-02-10T19:30:05-05:00 — #2
Have a look at the following jsFiddle which i created a simple demo in, basically it just creates a new element after the target element and increments the count with each click.
team1504 — 2012-02-10T22:01:45-05:00 — #3
hmm cool! that was exactly what i was looking for. :weee: thank you very much!
Do you know how one could limit the user to only clicking once? like a voting system?
chris_upjohn — 2012-02-10T22:30:46-05:00 — #4
If you only need the button to be clicked once then a counter isn't even needed, see the below jsFiddle which makes use of the element object to detect if it has been clicked.
team1504 — 2012-02-10T22:41:58-05:00 — #5
hmm okay, but why get rid of the counter
I was thinking of something that counts how many different people / computers voted or clicked the button. sorry if i was confusing before
chris_upjohn — 2012-02-10T22:44:29-05:00 — #6
team1504 — 2012-02-10T23:13:56-05:00 — #7
no it wouldn't. But then people could alter the vote by clicking countlessly. so would PHP need to be involved then?
do you know how one would check with the server to see if the user has voted and if they have then show the button and the total votes, but do not allow there votes to count; and, if they havent voted allow there one vote to count?
could that be done in PHP or Perl?