jquery - What is wrong with this javascript code? It keeps looping without stopping -


i have js code. works noticed error this. "typeerror: document.getelementbyid(...) null" , notice errors keeping counting in firebug. assuming it's loop keeps on going. can @ code below , tell me what's wrong it?

<script>  $( document ).ready(function() {        //create object list of due dates      //the 'name' correspond field id populate results      var duedates = {          'date1':'2017-04-17 09:55:18',          'date2':'2017-05-17 09:55:18',          'date3':'2017-06-17 09:55:18'      };        var timer = setinterval(function() {          //instantiate variables          var duedate, distance, days, hours, minutes, seconds, output;          //set flag repeat function          var repeat = false;          // todays date , time          var = new date().gettime();          //iterate through due dates          (var duedateid in duedates) {              //get due date record              duedate = new date(duedates[duedateid]);              // find distance between due date              distance = duedate - now;              // time calculations days, hours, minutes , seconds              days    = math.floor(distance  / (1000 * 60 * 60 * 24));              hours   = math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));              minutes = math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));              seconds = math.floor((distance % (1000 * 60)) / 1000);              //determine output , populate corresponding field              output = "overdue";              if (distance > 0)              {                  output = days + "d " + hours + "h " + minutes + "m " + seconds + "s";                  repeat = true; //if record not expired, set flag repeat              }              document.getelementbyid(duedateid).innerhtml = output;              //if flag repeat false, clear event              if(!repeat)              {                  clearinterval(timer);              }          }      }, 1000);  });  </script>
<div id="date1"></div>  <div id="date2"></div>  <div id="date3"></div>

your first due date future, distance positive, , repeat set true in first iteration of loop. never becomes false again inside loop, clearinterval function not executed in of for loop iterations. setinterval callback invoked again 1 second later, , same logic repeats...


Comments

Popular posts from this blog

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -