Revisit random loop and merge question | XM Community
Skip to main content

My survey has two parts. First, the respondent sees multiple instances of a block that prompt him for some numeric answer.
Something like: "In location X, the average daily temperature is _ ."
I want to randomly select 10 out of 100 locations, and was planning to do this using a loop & merge.
Later on in the survey, I want to revisit one of these locations, and I also need access to the respondent's answer. Is there a way to get access to one location fields that was chosen during the loop & merge, and also access its corresponding answer?

mimu
You can follow these steps:
1 Create a loop and merge with 1 field, and randomize it to present or run only 10 times.
2 Use that ${lm://Field/1} piped in where you would like to show the country name.
3 Create 20 embedded data's one which would have the country name and the second will have its value
4 Use javascript to push the country description name and its corresponding value into the embedded data. Replace the QID as per your question in below code. I have used c1,c1val, c2,c2val ... as variables only for two loop you can copy the if logic for all the 10 loops and different embedded datas.
Qualtrics.SurveyEngine.addOnReady(function()
{
jQuery("#"+this.questionId+" .InputText").on('blur',function(){
var q = "${q://QID14/QuestionText}";
var ln= "${lm://CurrentLoopNumber}";

if(ln==1){
Qualtrics.SurveyEngine.setEmbeddedData('c1',q);
  Qualtrics.SurveyEngine.setEmbeddedData('c1val', jQuery(this).val());
}
if(ln==2){
Qualtrics.SurveyEngine.setEmbeddedData('c2',q);
  Qualtrics.SurveyEngine.setEmbeddedData('c2val', jQuery(this).val());
}
});

});
5 By the end of 10 loops you will have 20 embedded data will be filled with 10 country names and 10 text entry values.
Hope it helps!


Leave a Reply