Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-27-2010, 07:48 AM   PM User | #1
reynoldscorb
New to the CF scene

 
Join Date: Jul 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
reynoldscorb is an unknown quantity at this point
Javascript Help, Click Counter

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.


<html>
<head>
<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;
}
</script>
</head>
<body>

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

</body>
</html>
reynoldscorb is offline   Reply With Quote
Old 07-27-2010, 08:32 AM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,036
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Well, as both variables are named counter you would expect that! 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

Last edited by Philip M; 07-27-2010 at 08:35 AM..
Philip M is offline   Reply With Quote
Old 07-27-2010, 03:32 PM   PM User | #3
reynoldscorb
New to the CF scene

 
Join Date: Jul 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
reynoldscorb is an unknown quantity at this point
Ahh. Thanks a lot!
reynoldscorb is offline   Reply With Quote
Reply

Bookmarks

Tags
counter, javascript

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:11 PM.


Advertisement
Log in to turn off these ads.