Auto-advance to next block after set amount of total time spent on a loop and merge block. | XM Community
Solved

Auto-advance to next block after set amount of total time spent on a loop and merge block.

  • 6 June 2020
  • 5 replies
  • 158 views

Userlevel 1
Badge +1

Hi Community,
I have a loop & merge block with only 1 (text entry) question in it:
********
Count the number of J's in the following string: ${lm://Field/1}
********
The loop & merge matrix is just 1 column with ~100 rows, each cell containing a string of random characters (e.g., "OJIJSDFOIJSDFOJSD").
Goal: Participants should have exactly 1 minute to answer as many questions (read: get through as many loops) as possible. They won't come anywhere close to getting through all 100 in the 1 minute, though.
The timer needs to be cumulative across all loops, so if someone spends 20 seconds on the first loop, and 10 seconds on the second loop, they should only have 30 seconds remaining for all remaining attempts. Then, at the end of the 1 minute, they should be auto-advanced to the next block.
Note: I do not want to show the timer on screen.
The Problem: I tried using the timer + auto-advance feature, but unfortunately it resets the timer with each successive loop.
What I've tried: Banging my head against a wall trying to implement THIS solution. No clue why I can't get it working.
FWIW, I suspect embedded data + JS + display logic together can accomplish this. I just don't know how.
I do not know JavaScript, so if anyone can point me toward any resources that would get this working, I'd be greatly appreciative.
Thanks!
PS: In case it's helpful, here's what I've tried:
flow.pngq.pngjs.png

icon

Best answer by TomG 6 June 2020, 22:57

View original

5 replies

Userlevel 7
Badge +27

start_timer should be initialized as:
start_timer = ${e://Field/Q_TotalDuration}

Userlevel 1
Badge +1

Hi TomG ,
Fantastic! Thanks so much!
The only strange thing now is that it seems to take much longer than my specified amount of time before it actually advances to the next page. i.e., I have it now specified to auto-advance after 10 seconds but it's actually taking something closer to 20 seconds or so to advance.
Any guesses?
If not, no sweat; you've already helped so much!
Here's the updated survey:
flow.pngq.pngjs.png

Userlevel 7
Badge +27

The way your script is written it isn't going to skip the remaining questions until the page after the current page times out when it loads and the respondent still has to click the next button. If you want it to auto advance as soon as elapsed time reaches 10 seconds you need to add a setInterval.

Userlevel 1
Badge +1

Oh, interesting! So I would just wrap the whole thing in a setInterval function, with the second interval as 300 (300 seconds = 5 minutes). Is that right? My attempt below. Again, I don't know JS so am super grateful for you, TomG.

Qualtrics.SurveyEngine.addOnload(function()

{

	/*Place your JavaScript here to run when the page loads*/

});

Qualtrics.SurveyEngine.addOnReady(function()

{

/*Place your JavaScript here to run when the page is fully displayed*/

setInterval{	

var start = parseInt('${e://Field/start_time}');

	var end = parseInt('${e://Field/Q_TotalDuration}');

	var elapsed = end - start;

	Qualtrics.SurveyEngine.setEmbeddedData('elapsed', elapsed);

	if(elapsed > 300) Qualtrics.SurveyEngine.setEmbeddedData('timeout', 1);

}),300};


Userlevel 7
Badge +27

No:

  1. You would just increment elapsed then set timeout and click the next button when time is elapsed in setInterval.

  2. setInterval timing is in milliseconds and you would run it every second (1000)

  3. You need a clearInterval before leaving the page

Leave a Reply