Force response with custom timer | XM Community

Force response with custom timer

  • 17 April 2018
  • 8 replies
  • 32 views

Hi All,

I have a custom timer with force response. The timer works fine without the Qualtric's force response feature. However, when I add force response, the last question before time is up always awaits a response before auto-advancing to the next block. Ideally I want the survey to auto-advance when time is up even if no response is submitted on the last question page within the timed block. Any suggestions on how to achieve this? I describe how I set up my custom timer below:

First, at the question that I want to declare as the start time, add this to the JavaScript editor:
Qualtrics.SurveyEngine.addOnPageSubmit(function()
{
Qualtrics.SurveyEngine.setEmbeddedData('StartTime', new Date().getTime());

});

Second, instantiate the StartTime embedded data field in the Survey Flow.

Third, choose “Look & Feel”, “Advanced”, add the following to the header source code:
!

Fourth, add the following to the header source code as well between <script> tags:
!

Fifth, under “Look & Feel”, “Advanced”, “Add Custom CSS”, add the following:
!

Finally, for the timed block, use display logic: display only if “StartTime” is greater than 0.

----------------------------------------------------------------------------------------------------
Thanks a lot for your help!

8 replies

Userlevel 7
Badge +27
What type of question is the last question in the block?
> @TomG said:
> What type of question is the last question in the block?

It's a text entry question. See below (same as my other question):
!
Userlevel 7
Badge +27
@Jiayi - You can have your timeout JavaScript write a "special" value to the text input (e.g. "Timed out") just before clicking the Next button (assuming you are going to uncomment the click Next).
> @TomG said:
> @Jiayi - You can have your timeout JavaScript write a "special" value to the text input (e.g. "Timed out") just before clicking the Next button (assuming you are going to uncomment the click Next).

That's a great idea! I added the following code right before clicking the Next button in the timeout JS, but it didn't work:

var inputbox = $(this.questionId).select('.InputText');
$(inputbox).insert('Timed Out');

Am I doing something wrong? Thanks!
Userlevel 7
Badge +27
`select` always returns an array. Use `down` since you just need to find the first (and only) input element. Then set the value. However, since your click Next is inside a function this.questionId isn't going to work, so set a question variable in the addOnload function.
```
var q = $(this.questionId);
```
Then:

```
q.down('.InputText').value = "Timed Out";
```
P.S. If you are going to be writing a lot of JS, you should consider switching to jQuery since prototypejs's time is numbered.
> @TomG said:
> `select` always returns an array. Use `down` since you just need to find the first (and only) input element. Then set the value. However, since your click Next is inside a function this.questionId isn't going to work, so set a question variable in the addOnload function.
> ```
> var q = $(this.questionId);
> ```
> Then:
>
> ```
> q.down('.InputText').value = "Timed Out";
> ```
> P.S. If you are going to be writing a lot of JS, you should consider switching to jQuery since prototypejs's time is numbered.

I added the two lines of code to the addOnload function but the timer simply disappears and I'm stuck with the last question page when time is up. Can this have to do with having the code globally in the Header?
Userlevel 7
Badge +27
@Jiayi - It could be any number of things. Without being able to look at it, I'd just be guessing. You should use console.log and/or a debugger to figure out what is going on.
> @TomG said:
> @Jiayi - It could be any number of things. Without being able to look at it, I'd just be guessing. You should use console.log and/or a debugger to figure out what is going on.

I used console.log to check on my code and found that "q" is "undefined", suggesting that "this.questionId" is not really working in the global header. I then tried putting the code in the block and adding a if statement to check if time left is < 0:

var leftTime = Qualtrics.SurveyEngine.getEmbeddedData('TimeLeft');
if (leftTime < 0) {
$(this.questionId).down('.InputText').value = "Timed Out";
console.log('Timed Out inserted');
jQuery('#NextButton').click();
}

This works fine, but the clicking skips one question after the timed block. I force the question to show by adding a force response for that question. And this solves the problem. However, I'm still not sure if the skipping can be avoided without using the force response feature.

Thanks for the help!

Leave a Reply