Displaying how many times a button/div is clicked

Hello,
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 :slight_smile:

Thanks in Advance & Best Regards,
Team 1504

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.

hmm cool! that was exactly what i was looking for. :weee: thank you very much! :slight_smile:

Do you know how one could limit the user to only clicking once? like a voting system?

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.

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 :blush:

The counter is user specific because JavaScript is a browser based language which doesn’t communicate with a server at any point in time unless your code tells it to, if you want a total count of how many people have clicked the button the vote count would be a clear indication of that wouldn’t it?

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?