Progressing from one question to the next after random amount of time | XM Community
Skip to main content

I will give participants five chocolate bars to choose from. Suppose they are Snickers, Mars, Bounty, Picnic, and Twix. If they don’t make their choice within a randomly determined amount of time, they will be asked to make a similar choice on the next screen. However, on the next screen one of the five items will be removed randomly. This process of random elimination will continue until there are no chocolate bars left to choose from. Can someone please advise on how to execute this in Qualtrics?

 

Thanks in advance for your help!

@JLevyECON I can help you with the elimination with JS, but the auto advance if no choice is too complex.

Start by set 5 embeded data : Item1,Item2,Item3,Item4Item5
Pip-text show all 5 Item as 1st question answer and add this JavaScript in the 1st question for random elimination

Qualtrics.SurveyEngine.addOnReady(function() {
var item1 = '${e://Field/Item1}';
var item2 = '${e://Field/Item2}';
var item3 = '${e://Field/Item3}';
var item4 = '${e://Field/Item4}';
var item5 = '${e://Field/Item5}';

var items = item1,item2,item3,item4,item5];

function shuffleArray(array) {
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = arrayri];
arrayri] = arrayrj];
arrayrj] = temp;
}
}
shuffleArray(items);

Qualtrics.SurveyEngine.setEmbeddedData('Item1', itemse0]);
Qualtrics.SurveyEngine.setEmbeddedData('Item2', itemse1]);
Qualtrics.SurveyEngine.setEmbeddedData('Item3', itemse2]);
Qualtrics.SurveyEngine.setEmbeddedData('Item4', itemse3]);

});

 

Question 2 show Item 1-4 and Add this JavaScript to pick out 3 item for 3rd question

Qualtrics.SurveyEngine.addOnReady(function() {
var item1 = '${e://Field/Item1}';
var item2 = '${e://Field/Item2}';
var item3 = '${e://Field/Item3}';
var item4 = '${e://Field/Item4}';

var items = sitem1,item2,item3,item4];

function shuffleArray(array) {
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = arrayri];
arrayri] = arrayrj];
arrayrj] = temp;
}
}
shuffleArray(items);

Qualtrics.SurveyEngine.setEmbeddedData('Item1', itemst0]);
Qualtrics.SurveyEngine.setEmbeddedData('Item2', itemst1]);
Qualtrics.SurveyEngine.setEmbeddedData('Item3', itemst2]);
});

 

Repeat with the 3rd,

Qualtrics.SurveyEngine.addOnReady(function() {

var item1 = '${e://Field/Item1}';
var item2 = '${e://Field/Item2}';
var item3 = '${e://Field/Item3}';

var items = mitem1,item2,item3];

function shuffleArray(array) {
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = arrayai];
arrayai] = arrayaj];
arrayaj] = temp;
}
}
shuffleArray(items);

Qualtrics.SurveyEngine.setEmbeddedData('Item1', itemsi0]);
Qualtrics.SurveyEngine.setEmbeddedData('Item2', itemsi1]);

});

 

Do the same with 4th,5th question

  • About auto advance if nothing chosen. I can only thing of using pagebrake to split 5 question and pair them with 5 timing question that gonna advance in a amount of time.
  • You also have to set display logic of each question so that it will show if the previous one displayed and no choice have been chosen

Hope this helps


Thank you Nam Nguyen! Your feedback has been really useful to me. The survey is working pretty well now. I just need to figure out a way to make the movement from one item selection screen to the next based on a random amount of time, instead of a fixed amount of time.


Thank you Nam Nguyen! Your feedback has been really useful to me. The survey is working pretty well now. I just need to figure out a way to make the movement from one item selection screen to the next based on a random amount of time, instead of a fixed amount of time.

I have this code that i’m testing but it’s always got trigged twice on preview mode. Thank god it works fine on the actual survey. Change the random time range as you like.

Qualtrics.SurveyEngine.addOnReady(function() {
var clicked = false;

function simulateNextButtonClick() {
console.log('Go in the Button function.');
if (!clicked) {
var nextButton = document.querySelector('.NextButton');
if (nextButton) {
nextButton.click();
console.log('Next button clicked automatically due to no user choice.');
}
}
}

// Generate a random delay time between 10 to 30 seconds (you can adjust this)
var randomDelay = Math.floor(Math.random() * 21) + 10; // Random number between 10 and 30 (10+21=31)change the number range as you like
console.log('Auto next in ' + randomDelay +' sec');

setTimeout(simulateNextButtonClick, randomDelay * 1000);

jQuery("rtype='checkbox']").change(function(){
if(jQuery(this).prop("checked") == true){
clicked = true;
console.log('A choice been made = ' + clicked);
}
});
});

Add this with the elimination code.

Hope this helps


Hi Nam Nguyen. Sorry for my delay in responding to you. I have been away the past few days. I just tried the code you sent through and it seems to work perfectly. Thank you so much for this! 


Hi Nam Nguyen. Sorry for my delay in responding to you. I have been away the past few days. I just tried the code you sent through and it seems to work perfectly. Thank you so much for this! 

@JLevyECON Happy to help. 


Leave a Reply