If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Make a button counter

Hello,
I am somewhat new to javascript but I hope you can help me out.

What I am looking to do, is make an image clickable, and when the image is clicked it increases a counter. Pretty much I want to know how many times the button has been clicked. It would be great if this was all done real time as well. If anyone has any ideas I would greatly appreciate that.

ECMAscript (JavaScript) does all its operations on the client-side, so if you are operating a server, you need to set up a persistent connection or session with the user's browser and have the click events sent to you, where you likely operate the counter from the server end.

Your best bet is to set up a simple Ajax interface, which does the client->server transmission of information, where you can be informed of the click events and then record them in your database as needed.

Hey tirna,
That is almost exactly what I need. The intention is to keep how many times the button is clicked from everyone, so the variable would need to be global. and increase for every person that is on the page.
Not sure if there is something I should do to keep this server side.

@tirna

hEY. i FOUND YOUR CODE VERY USEFUL. I WAS WONDERING IF THERE WAS ANYWAY THE COUNTER CAN BE EDITED SO THAT IT IS ON THE SIDE OF THE BUTTON AND CLOSE TOO
AS OPPOSED TO BEING ON THE BOTTOM AND WAY DOWN?
YOU ARE AWESOME

I am a knitter, and an android user. I need, and haven't been able to find, an app that I can use on my tablet and phone and be shown the same data from the last update on whatever device.

My ultimate goal would be to have a page where I can add/delete/select projects and then go to the associated counter.

I haven't practiced what JS/PHP I learned a few years back so trying to jump back in is just a little difficult. At the moment I have some goofy looking html/css but I'm not sure how to implement my functions from my external file. When the "+" button is clicked I'd like to see the Row/repeat number increase by 1 and subtract 1 for everytime the "-" button is clicked. However, what I have right now doesn't update when the buttons are clicked. For the time being I'm playing with the Row counter so that I can implement the same code for the repeat counter. Please pardon the design bugs for now, I'm looking for getting my functionality going and would like to just see it work already! I uploaded my code here for those that would like to see what I have: http://thedevplace.info/counter/counter.php

Once I do get it working, I could also use some advice on what to do next in terms of making this work across several devices. I assume I'd have to generate and query a database but getting data in/out etc would be another issue I'll have to cross.