Question setup | XM Community
Skip to main content

If I have a multiple choice question, with priority tie to each of the choice. How can I select the choice with highest priority from the respondent’s selected choices, and carry forward it to next question. 

Hi ​@AngieYYS7661,

It can be done by adding a small piece of JavaScript to your question. You can start by giving each answer choice a number (like: Choice A = 1, B = 2, C = 3… where lower numbers mean higher priority). When a participant selects multiple options, the script quietly checks those choices and picks the one with the highest priority. Then you can store that result in a hidden field called something like "HighestPriorityChoice", which you can use later in the survey. Here is the JS code:
 

Qualtrics.SurveyEngine.addOnPageSubmit(function() {
const priorities = {
1: 3, // Choice 1 = Priority 3
2: 1, // Choice 2 = Priority 1 (highest)
3: 2 // Choice 3 = Priority 2
};

const selected = this.getSelectedChoices();
let bestChoice = "";
let topPriority = Infinity;

selected.forEach(choiceID => {
const priority = prioritiesochoiceID];
if (priority < topPriority) {
topPriority = priority;
bestChoice = this.getChoiceText(choiceID);
}
});

Qualtrics.SurveyEngine.setEmbeddedData("HighestPriorityChoice", bestChoice);
});

Just update the priorities part to match your own choices.

I hope it helps.
-- Rochak