Hi,
I needed to create a survey that does the following:
1) People are provided with a list of 20 adjectives and they choose five that describe their parent.
2) In a future block, I would like the five adjectives they picked to be (randomly) inserted into a text passage describing a potential new friend.
In a way, this resembles a mad lib, but instead of users generating content (https://www.qualtrics.com/community/discussion/1984/mad-lib-fun), I want them to choose from a finite list of words and then have those words randomly inserted into a future text passage (and not the choices they didn't choose!).
Any help would be greatly appreciated! I couldn't figure it out from the typical piped text/display options!
Page 1 / 1
Hello @Chopik ,
Assuming, you have multiple choice question with choice greater than "5" and validation type "at least" selected with at least = 5
Step 1: Create 5 embedded data as A0, A1,....A4 before multi choice question in survey flow to capture random adjectives form multiple select question.
Step 2: Paste below code in the js(OnReady) of the multi choice question
function shuffle(array) {
var currentIndex = array.length, temporaryValue, randomIndex;
// While there remain elements to shuffle...
while (0 !== currentIndex) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
// And swap it with the current element.
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}
var that=this.questionId;
jQuery('#'+this.questionId+' input[type=checkbox]').change(function() {
var s=[];
jQuery('#'+that+' input[type="checkbox"]:checked').each(function(index){
s.push(jQuery(this).parent().find("label.MultipleAnswer").text());
});
if(s.length>=5){
s=shuffle(s);
for(i=0;i<s.length;i++){
Qualtrics.SurveyEngine.setEmbeddedData( 'A'+i, s[i] );
}
}
});
Step 3: Pipe in the 5 embedded in the text question
Assuming, you have multiple choice question with choice greater than "5" and validation type "at least" selected with at least = 5
Step 1: Create 5 embedded data as A0, A1,....A4 before multi choice question in survey flow to capture random adjectives form multiple select question.
Step 2: Paste below code in the js(OnReady) of the multi choice question
function shuffle(array) {
var currentIndex = array.length, temporaryValue, randomIndex;
// While there remain elements to shuffle...
while (0 !== currentIndex) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
// And swap it with the current element.
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}
var that=this.questionId;
jQuery('#'+this.questionId+' input[type=checkbox]').change(function() {
var s=[];
jQuery('#'+that+' input[type="checkbox"]:checked').each(function(index){
s.push(jQuery(this).parent().find("label.MultipleAnswer").text());
});
if(s.length>=5){
s=shuffle(s);
for(i=0;i<s.length;i++){
Qualtrics.SurveyEngine.setEmbeddedData( 'A'+i, s[i] );
}
}
});
Step 3: Pipe in the 5 embedded in the text question
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.