Javascript Counter

Associate
Joined
7 Sep 2003
Posts
1,897
Location
Bo'ness
Hey

I am a noob to JavaScript so sorry if this is a stupid question. I am trying to make a counter that counts how many times a user clicks on a image but I cannot get it to work.

Javascript code

Code:
 <script type="text/JavaScript">
function add()
{
count = count + 1
alert(count)
}
</script>

Pic Code

Code:
<img src="cards/s2.gif" onclick= "add()"/>


My best guess is it is something to do with me having the same variable inside that variable if you get me. When I change the variable inside “count” to just a number it adds them fine.

Any help would be great

Thanks
 
Last edited:
Code:
<script type="text/javascript" language="JavaScript">
var count = 0;
function add()
{
count = count + 1;
alert("Count is " + count);
}
</script>
 
Back
Top Bottom