I have developed a JavaScript countdown timer; also I have a SharePoint list that retrieves the minutes for countdown and its column name is Koha

I am retrieving Koha and initializing in a variable; But when I try running the app the countdown timer shows me NaN?

This is how I am retrieving Koha field:

    function Retrieve(){
    currentQuizItem = quizList.getItemById(quizID);
    var quizName;

    var koha = currentQuizItem.get_fieldValues()["koha"];

    //even if I try to convert it to number it does not work
    koha = parseInt(Koha);

    alert(koha); // here I can see my value but later when I initialize this var to countdown it says NaN;


This is my JavaScript countdown timer

function startTimer(duration, display) {
  var timer = duration, minutes, seconds;
  setInterval(function () {
    minutes = parseInt(timer / 60, 10);
    seconds = parseInt(timer % 60, 10);
    minutes = minutes < 10 ? "0" + minutes : minutes;
    seconds = seconds < 10 ? "0" + seconds : seconds;
    display.textContent = minutes + ":" + seconds;
    if (--timer < 0) {
        timer = duration;
 }, 1000);

window.onload = function () {
   var fiveSec = 60 * koha,   //If I make this 60 * 20 it works and there are 20 min to countdown
   display = document.querySelector('#UItimer');

  startTimer(fiveSec, display);

Now when I run my app if shown me NaN:NaN instead of showing me timer

please help me

  • Same thing you are missing again executeQueryAsync() Aug 5 '16 at 10:15
  • where I have to place executeQueryAsync() now? Aug 5 '16 at 10:25
  • I have Added executeQueryAsync() just like you did un my previous question but still getting the error NaN:NaN Aug 5 '16 at 10:29

I think you need to run executeQueryAsync after context.load

clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));  


This issue is related to window.onload = function () { the So the field koha is empty when you execute it onload function, you should start the calculate of fevsec after you got kohe value.

  • I placed the function() but still getting NaN:NaN but If I alert(koha) it shows me the value i.e 45 in my case Aug 5 '16 at 10:27
  • try to alert also fiveSec and check its value may be the issue not related to code now and related to display variable display = document.querySelector('#UItimer'); , Are you tried to show it manually without retrieving from list , is it worked properly ?! Aug 5 '16 at 10:31
  • #UItimer displays the fivesec; i am retrieving the item but still can't make it to work I can share my code to you if you want Aug 5 '16 at 10:35
  • share the code and please invite me to chat room to check it Aug 5 '16 at 10:37
  • chat.stackexchange.com/rooms/43505/… this is our conversation Aug 5 '16 at 10:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.