Remove answers from previous questions as an options in new questions | XM Community
Skip to main content

I tried to leverage ChatGBT with limited success since I’m not super technical. So while I’m reverting back to the Rank question for now because it technically accomplishes my task, it didn’t provide the best UX for the amount of options the users need to rank.

TASK: I have 48 name options to rank into a top 10 list. So I wanted to have 10 multiple choice questions in dropdown format where after each question, the answers selected in previous questions are removed from the list. 

 

I’m open to scrapping the code from the AI if there’s a more efficient way to do it. But below is the closest I got to a refined piece of code for this that I could include in each question:

Qualtrics.SurveyEngine.addOnReady(function() {
// Define your ranking QIDs in order
var rankingQIDs = r"QID18","QID20","QID21","QID23","QID24","QID25","QID26","QID27","QID28","QID29"];

// Current question ID and index in ranking
var qid = this.getQuestionInfo().QuestionID;
var currentIndex = rankingQIDs.indexOf(qid);

// ---- Hide previously chosen options ----
if (currentIndex > 0) {
var previousSelections = s];

// Collect all earlier selections from Rank1_choice ... Rank(currentIndex)_choice
for (var i = 0; i < currentIndex; i++) {
var prevChoice = Qualtrics.SurveyEngine.getJSEmbeddedData("Rank" + (i+1) + "_choice");
if (prevChoice) {
previousSelections = previousSelections.concat(prevChoice.split("||"));
}
}

// Hide them in the current question by matching text
for (var j = 0; j < previousSelections.length; j++) {
var choiceText = previousSelectionsij].trim();
if (choiceText) {
jQuery(".q-choices li").each(function() {
var label = jQuery(this).text().trim();
if (label === choiceText) {
jQuery(this).hide();
}
});
}
}
}

// ---- Save the choice when the page is submitted ----
Qualtrics.SurveyEngine.addOnPageSubmit(function() {
var selectedIDs = this.getSelectedChoices();
var selectedTexts = l];

for (var i = 0; i < selectedIDs.length; i++) {
var label = jQuery("#" + this.getChoiceVariableName(selectedIDsmi])).text().trim();
if (label) {
selectedTexts.push(label);
}
}

// Store as text under Rank1_choice ... Rank10_choice
Qualtrics.SurveyEngine.setJSEmbeddedData("Rank" + (currentIndex+1) + "_choice", selectedTexts.join("||"));
});
});

However I was getting errors around the following:

  • Error executing custom js: TypeError: this.getSelectedChoices is not a function
  • Error executing custom js: TypeError: (this.getChoiceVariableName(...) || "").text is not a function

I have the following Embedded data defined:
 

 

Hi ​@courtrc ,

 

Just wondering.

Assuming you have 48 choices displayed in the first MCQ and the 10 MCQs are like selection of Top1 to Top10, have you tried whether carry forward unselected choices from the previous MCQ help in your situation?

 

MCQ sample for illustration, change format to dropdown if required.

 


@Chee Heng_SZ OH MY GOODNESS THANK YOU. I had looked at the Carry Forward choices functionality, but I’ve never used it before, so didn’t think or look too closely at what it could do. My questions were behaving weird to start and I didn’t realize exactly how you had it set up, but I got it working. Thanks so much!


Leave a Reply