View Full Version : Javascript Help, Click Counter

07-27-2010, 08:48 AM
Hey Everyone,

I'm trying to set up two different buttons that count their own individual clicks.

So far I have everything except where one button leaves off, the other picks up. So if I click the left one three times it shows the number 3, and then if I click the button next to it, that button picks up at 4. I want each button to have its own count.

Any ideas?

Here's what I have so far.

<script type="text/javascript">
var counter = 0;
function increaseloveit() {
counter += 1;
document.getElementById('loveit').value = counter;
var counter = 0;
function increasehateit() {
counter += 1;
document.getElementById('hateit').value = counter;

<a href="#" onclick="javascript:increaseloveit();"><input type="button" value="Love It!" name="loveit" onclick="" /></a><input id="loveit" value="0" size="2" /></form>
<a href="#" onclick="javascript:increasehateit();"><input type="button" value="Hate It!" name="hateit" onclick="" /></a><input id="hateit" value="0" size="2" /></form>


Philip M
07-27-2010, 09:32 AM
Well, as both variables are named counter you would expect that! :rolleyes: Name them counterA and counterB or something.

I expect you realise that the number of clicks recorded will apply only to that particular user in that browser session. If you are trying to create a poll where all users can see the results you will need server-side scripting.

"Think about how stupid the average person is, and then realize that half of them are more stupid than that!" - George Carlin

07-27-2010, 04:32 PM
Ahh. Thanks a lot!