1.11M Members

click counter

 
0
 

Hi, I am trying to make a click counter.
The prolem is the onClick part in button code.
If i made it so it was "click();" and placed the var clicks into the function click then it would kind of work.
But when I pass a variable into it.. it won't.
Thanks.

<html>
<head>
    <h1 align = center>Javascript Dump</h1>
</head>
<script type ="text/javascript">
var clicks = 0;
function click(clicks){
    x += 1;
    document.getElementById("counter").value = x;
}
</script>
//button code
<input type = "button", value = "0", onClick = "click(clicks);", id = "counter">
</html>
 
0
 

because when u pass "click" variable in fucntion, it overrides global "click". so do it without function variable.

 
0
 

For some reason, the function cannot be called click... its probably a keyword. Here is an updated version based on your code. Please note that some of your elements were in the wrong place and you were missing some structural HTML elements.

The sample below will increase the value and store it within the button's value property.

<!DOCTYPE html>
<html>
<head>
<script>
var x=0;
function clickMe(){
    x = x +1;
    document.getElementById("counter").value = x;
}
</script>    
</head>
<body>
<h1>Javascript Dump</h1>
<input id="counter" type="button" value="0" onclick="clickMe();" >
</body>
</html>
 
0
 

Thanks alot clears things up alot.

Question Answered as of 1 Year Ago by urtrivedi and JorgeM
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article