PDA

View Full Version : adding to variable


chrismiceli
09-17-2002, 11:00 PM
how can i get js to add just one to this variable

var hit = 0

I tried this but after a few times of the onClick() (that is how i add something to the hit variable) it adds two each time I beleive.

hit ++, I also tried
hit = hit + 1

umm
09-17-2002, 11:21 PM
like this perhaps?

<html>
<head>
<title>
</title>
<script language="javascript" type="text/javascript">
<!-- ;
function foo(){
var hit=0
if(hit==0){
hit++
alert(hit)
}
}
// -->
</script>
</head>

<body>
<a href="javascript:void foo()">nnnnn</a>
</body>
</html>

chrismiceli
09-17-2002, 11:25 PM
this is the script, it should only take 4 clicks to make it disabled but it is taking 7, if the number is anything under three (postive) it works, but on 3 or above it takes a whole bunch of clicks.

<html>
<head>
<title>test</title>
<script language="javascript">
var hit = 0
function test() {
hit++
if (hit > 3) {
document.hi.hit.disabled=true;
}
}
</script>
</head>
<form name="hi">
<input type="button" name="hit" value="hi" onClick="test()">
</form>
</form>
</body>
</html>

umm
09-18-2002, 01:20 AM
hmmm, that actually works ok for me. 4 clicks and it's disabled

chrismiceli
09-18-2002, 01:31 AM
i was clicking too fast it wasn't rendoring all of the clicks because the button didn't pop back up yet. LOL:)