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!
Best answer by Nam Nguyen
JLevyECON wrote:
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;
functionsimulateNextButtonClick() {
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("[type='checkbox']").change(function(){if(jQuery(this).prop("checked") == true){
clicked = true;
console.log('A choice been made = ' + clicked);
}
});
});
@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
Hide contentShow content
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];
functionshuffleArray(array) {for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
shuffleArray(items);
Qualtrics.SurveyEngine.setEmbeddedData('Item1', items[0]);
Qualtrics.SurveyEngine.setEmbeddedData('Item2', items[1]);
Qualtrics.SurveyEngine.setEmbeddedData('Item3', items[2]);
Qualtrics.SurveyEngine.setEmbeddedData('Item4', items[3]);
});
Question 2 show Item 1-4 and Add this JavaScript to pick out 3 item for 3rd question
Hide contentShow content
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 = [item1,item2,item3,item4];
functionshuffleArray(array) {for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
shuffleArray(items);
Qualtrics.SurveyEngine.setEmbeddedData('Item1', items[0]);
Qualtrics.SurveyEngine.setEmbeddedData('Item2', items[1]);
Qualtrics.SurveyEngine.setEmbeddedData('Item3', items[2]);
});
Repeat with the 3rd,
Hide contentShow content
Qualtrics.SurveyEngine.addOnReady(function() {var item1 = '${e://Field/Item1}';
var item2 = '${e://Field/Item2}';
var item3 = '${e://Field/Item3}';
var items = [item1,item2,item3];
functionshuffleArray(array) {for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
shuffleArray(items);
Qualtrics.SurveyEngine.setEmbeddedData('Item1', items[0]);
Qualtrics.SurveyEngine.setEmbeddedData('Item2', items[1]);
});
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
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;
functionsimulateNextButtonClick() {
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("[type='checkbox']").change(function(){if(jQuery(this).prop("checked") == true){
clicked = true;
console.log('A choice been made = ' + clicked);
}
});
});
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!