user3645251 user3645251 - 2 years ago 272
Javascript Question

JavaScript button?

I want to make a button that adds on 0.00142 each time and I've created a simple JavaScript function but it doesn't seem to work?

Any help? Thanks! :)

<input type="button" value="Count" id="countButton" />

<p>You've burned <span id="displayCount">0</span> Calories!</p>

<script type="text/javascript">
var count = +0.00142;
var button = document.getElementById("countButton");
var display = document.getElementById("displayCount");

button.onclick = function(){
count++;
display.innerHTML = count;
}
</script>

Answer Source
<script type="text/javascript">
  var total = 0;
  var count = 0.00142;
  var button = document.getElementById("countButton");
  var display = document.getElementById("displayCount");

  button.onclick = function(){
    total = total + count;
    display.innerHTML = total;
  }
</script>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download