Have an idea?

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

How to determine if a JavaScript timer has expired?

When using a JavaScript timer, how can I tell the timer has actually timed out? Is there a variable or parameter that can assist as I'd like to use it?
I have used the following script ...
<script type="text/javascript">
   window.onload = function () {
   setTimeout('SSI_SubmitMe()', 10000);

Later in my survey, I would like to use the condition ...

  do condition

asked Apr 13, 2015 by Paul Moon Platinum (98,670 points)

1 Answer

0 votes
Create a variable in a free format question on the same page and put the code in there. In this case I named the question FFquest, with a hidden text variable called FFquest_timeout. When the page times out it will change the value from "no" to "yes".

<input type="hidden" id = "FFquest_timeout" name="FFquest_timeout" value="no">
<script type="text/javascript">
   window.onload = function () {
        document.getElementById('FFquest_timeout').value = "yes";
    }, 10000);

Then later on you can check it the way you'd normally reference a response in skip logic, or pipe it into your JavaScipt or Perl code with the Value function. (note I have it as a text variable so if you do the same make sure to put quotes around it if you pipe it in to JavaScript/use the correct Perl operator in your if statement)
answered Apr 13, 2015 by Nolan Kaplan Bronze (4,090 points)
edited Apr 13, 2015 by Nolan Kaplan
Appreciate your timely response Nolan. Thank you.