because when u pass "click" variable in fucntion, it overrides global "click". so do it without function variable.
urtrivedi
Posting Virtuoso
1,714 posts since Dec 2008
Reputation Points: 299
Solved Threads: 362
Skill Endorsements: 24
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>
JorgeM
Industrious Poster
4,017 posts since Dec 2011
Reputation Points: 294
Solved Threads: 548
Skill Endorsements: 115
Question Answered as of 5 Months Ago by
urtrivedi
and
JorgeM