• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 741
  • Last Modified:

javascript counter using seconds

Hello
  I want to create a counter that acts something like a clock.  The logic is this, a person dies from smoking every 8 seconds.  I want to know how many have died just this year - somewhere around 950,400 so far this year.  I would like to include the 'clock' on a website.

Thanks a ton!
JG
0
JGoyer
Asked:
JGoyer
  • 2
1 Solution
 
Pravin AsarCommented:
<html>
<head>
<title>Counter Document</title>
</head>

<body onLoad="MyCounter(); window.setInterval(MyCounter,8000);">
<script language="javascript">
function MyCounter () {
      var dt1 = new Date ('01/01/2006');
      dt1.setMinutes(0);
      dt1.setHours(0);
      dt1.setSeconds(0);
      var dt2 = new Date ();
      var diff = dt2 - dt1;
      //alert ('Number of people ' + (parseInt (diff)/(8*1000)).toFixed(0));
      var spanObj = document.getElementById('counter');
      if (spanObj) {
            spanObj.innerHTML = 'Number of people ' + (parseInt (diff)/(8*1000)).toFixed(0);
      }
}
</script>
<span id="counter">GO HERE </span>
</body>
</html>
0
 
bgloddeCommented:
0
 
Pravin AsarCommented:
JGoyer,

Just follow-up.. does my solution useful ??

_PA
0
 
JGoyerAuthor Commented:
awesome!  thanks!
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now