asked on December 1, 2021 Show version history

Hi,

I have the following JS for a timer:

$("target").prop ("checked", true);
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);
}

how do I start the timer with the "Yes" click of radio button #q24?

It currently starts when the page loads, so when you click the radio button "Yes" it's already 4-5 seconds into the countdown.

Any help would be appreciated.

0 0