Nel

Nel

  • NA
  • 716
  • 1m

Indicator for how much time is left

Sep 24 2014 7:25 AM

Hello,
I have a web page with a displayed google map and every several seconds the values are updated automatically on the map. Can anybody tell me please how to place an indicator that will show how much time is left for the next update?
For the timer I have this in the java script
 var tim=<%= Session["21"] %>*1000;
  setInterval(function(){ initialize();}, tim);
Thanks
I tried like this, but doesn't work
function startCountdown(timeLeft) {
  var interval = setInterval( countdown, tim*1000 );
  update();
  function countdown() {
  if ( --timeLeft > 0 ) {
  update();
  } else {
  clearInterval( interval );
  update();
  completed();
  }
  }
  function update() {
  hours  = Math.floor( timeLeft / 3600 );
  minutes = Math.floor( ( timeLeft % 3600 ) / 60 );
  seconds = timeLeft % 60;
  setInterval(function(){ initialize();}, tim*1000);
  document.getElementById('time-left').innerHTML = '' + hours + ':' + minutes + ':' + seconds;
  }
  function completed() {
  alert('Time Up!');
  //Your Logic here
  //setInterval(function(){ initialize();}, tim*1000);
  }
  }
...
..
<body onload="initialize()"; "startCountdown(20)"; style="padding: 1em">
...
...
Time Left <span id="time-left"></span>
Can anybody help me please?

Answers (2)