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.
Question setup
Best answer by rochak_khandelwal
Hi
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 = priorities[choiceID];
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
Sign up
Already have an account? Login
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join.
No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login with Qualtrics
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join. No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login to the Community
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join.
No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login with Qualtrics
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join. No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
