0

I am trying to use javascript's setInterval() function to create a timer that actions at certain times, however the following Javascript which works outside of Visualforce, jumps from 0 to a random number 1 to about 200 as soon as setInterval is invoked in visualforce.

Is this a bug or am I missing something?

function startTimer() {
    loadingOn('workspaceLoading');
    waitCounterNew = 0;
    console.log('attemptCount: ' + attemptCount);
    attemptCount = setInterval(function () {
        console.log('attemptCount: ' + attemptCount);
        console.log('waitCounterNew : ' + waitCounterNew);
        waitCounterNew += 1;
        if (attemptCount > 2) {
            attemptCount = 0;
            alert('This has failed');
            stopTimer();
            resetTimer();
        }

        if (counter > 10) {
            loadingOff('workspaceLoading');
            stopTimer();

        }

        j$("#output").html(waitCounterNew + 'second(s) has passed - ' + attemptCount + ' Try');

    }, 1000);
    j$("#intID").html(attemptCount);


}
  • attemptCount: 0 --> First Console Log
  • attemptCount: 62 --> Second Console Log

Your Answer

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

Browse other questions tagged or ask your own question.