Timing count based on embedded data | XM Community
Solved

Timing count based on embedded data


Hi Qualtrics friends,

In my survey I make use of timing questions. Per page, I want to vary how many seconds the participant will be auto-advanced to the next page. I also have multiple-choice questions for which I have scored the answers. I would like to use these answers to set the timer in the next page. For example, if someone answers in the multiple-choice question '10', I would like to have the timer on '10 seconds' in the next page. In the end, I would like to set the timer based on a whole scoring category, so not based on just one question. Is this possible at all?

Thanks in advance for all the help!
icon

Best answer by TomG 29 May 2019, 16:56

View original

8 replies

Userlevel 7
Badge +27
It isn't possible using a timing question. It is possible using JavaScript to do the timing.
> @TomG said:
> It isn't possible using a timing question. It is possible using JavaScript to do the timing.

Thank you for you answer. I tried to do it with JavaScript, and to start off I used the code

this.hideNextButton();
var that = this;
(function(){that.clickNextButton();}).delay(5);

I am quite new to coding. Any suggestions where I have to create the variable that contains embedded data to replace that '5'? i.e., How can I access a scoring category in JS?
Userlevel 7
Badge +27
> @"Joël" said:
> this.hideNextButton();
> var that = this;
> (function(){that.clickNextButton();}).delay(5);
>
> I am quite new to coding. Any suggestions where I have to create the variable that contains embedded data to replace that '5'? i.e., How can I access a scoring category in JS?
You can pipe an embedded variable or a score into your JS. It will come in as a string so convert it to an integer:
```
this.hideNextButton();
var that = this;
(function(){that.clickNextButton();}).delay(parseInt("${e://Field/delaysecs}"));
```
Yes I got it, thanks a lot!

https://www.qualtrics.com/community/discussion/comment/14681#Comment_14681Hi, TomG, may i ask a follow-up question? I notice that if people finish the questions earlier and click the next button by themselves to proceed to next block earlier, these commands still work and make people proceed to the third block. How can I prevent this? Thanks!

Userlevel 7
Badge +27

https://www.qualtrics.com/community/discussion/comment/38051#Comment_38051So, the code provided by the OP is using prototypejs which I wouldn't use myself. I would use setTimeout. If you record it to a variable they you can use clearTimeout to cancel it. Something like:
var to = setTimeout(function() { that.clickNextButton(); },5000);
Qualtrics.SurveyEngine.onPageSubmit(function() { clearTimeout(to); });

https://www.qualtrics.com/community/discussion/comment/38055#Comment_38055Thanks for the reply. My case is a bit more complex. I paste my code here:
var timeout = setTimeout(function (){jQuery("#NextButton").click();}, 20000);

jQuery('#SvcButton').on('click', () => {
jQuery("#NextButton").click();
clearTimeout(timeout);});
I use the clearTimeout function if another button (SvcButton) is clicked (people will advance to next block so the nextbutton click function should be cleared), but it seems like the settimeout function still works. How can i solve this problem?
My idea was to create a customised next button for this block so that even if the settimeout function still works, it will not click next block's next button. But do you have any other solution or do you know how can i change the scripts? Many thanks!!

https://www.qualtrics.com/community/discussion/comment/38055#Comment_38055I tried several times:
var Q119 = setTimeout(function(){jQuery("#QID119").show();}, 20000);
var Advance = setTimeout(function (){jQuery("#NextButton").click()}, 30000);

jQuery('#SvcButton').on('click', () => {
jQuery("#NextButton").click();
clearTimeout(Q119);
clearTimeout(Advance);
});
It works for var Q119 but it does not work for Advance, the next button in the following block will still be clicked and proceed to the third block. Do you know where is the problem? Thanks!!!

Leave a Reply