Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Display a timer

I am in need of some script that displays a timer somwhere on my survey page.

I have to display a 3 minute timer on one survey page and a 45 second timer on another survey page.

If the respondent submits their answers before the timer expires, that's fine. Proceed onwards ...

If the timer expires in either case, I don't need to do anything except say something like "Your time has expired and has been recorded."

Can the timer be displayed in the format #m:##s?

Thanks.
asked Aug 11, 2017 by Paul Moon Platinum (98,670 points)

2 Answers

+1 vote
Place this HTML where you want the timer to appear:

<span class="timerCountdown">3:00</span>
<span class="timerExpired">Expired</span>


CSS can hide the expired message by default:

<style>
.timerExpired {
    display: none;
}
</style>


And finally the JS:

<script>
$(document).ready(function(){
    var timer = 3 * 60;
    var interval = setInterval(function(){
        timer--;
        var minute = parseInt(timer / 60);
        var second = timer % 60;
        second = ('0' + second).slice(-2);
        $('.timerCountdown').text(minute + ':' + second);
        if (timer == 0) {
            $('.timerCountdown, .timerExpired').toggle();
        }
    }, 1000);
})
</script>
answered Aug 11, 2017 by Zachary Platinum Sawtooth Software, Inc. (205,575 points)
Thanks Saurabh and Zachary.

Zachary, I have it working for the 3min and 45sec versions. Much appreciated.

Saurabh, feel free to send your code through when you get a chance.
0 votes
I have made a timer in past like this:

https://scriptbox.sawtoothsoftware.com/generalprogramming/cgi-bin/ciwweb.pl?studyname=generalprogramming&id=test&q=60

If something like this serves the purpose, I can send you code
answered Aug 11, 2017 by Saurabh Aggarwal Gold (34,795 points)
Thanks Saurabh.

I like the actual timer. I don't need any auto submit functionality, just the timer counting down to zero.

Does it come in a #m:##s format?

And when it expires, can it be replaced with a message like "Your time has expired and has been recorded."?
Hi Saurabh,

I have just checked your demo https://demo.sawtoothsoftware.com/adtest/cgi-bin/ciwweb.pl?hid_studyname=adtest&hid_pagenum=0

can you please send me the code for it. I have worked on all the things but unable to get the time for test ad, can you say me how to do for it.

Much appreciated :)
...