Default choices on a series of multiple choices questions, based on previous answer | XM Community
Skip to main content

Hi everyone,

I have a question about setting up different default preselected options based on the answer to a previous question in the survey. Here's the scenario:

In the survey, there are two multiple choice questions:

Question 1 (Q1): Participants indicate their country of residence among three options: Spain, Germany, or Sweden.

Question 2 (Q2): This question offers three choices: Black, Orange, and Yellow.

Now, what I want to achieve is to dynamically change the default preselected option in Q2 based on the answer given in Q1. Here's the desired behavior:

  • If a participant selects Spain in Q1, the default option in Q2 should be "Orange."
  • If a participant selects Germany in Q1, the default option in Q2 should be "Yellow."
  • If a participant selects Sweden in Q1, the default option in Q2 should be "Black."

I'm seeking guidance on how to implement this logic (javascript)?

Thank you!

I hope both questions are appearing on separate pages. You can use JS and based on Q1 selection you can punch answer option of Q2 on page load of Q2.


You are right @ArunDubey, the two questions appear on separate pages. Perhaps you have any example of a js I could look to learn how to adapt it to my case? Thank you!


@MNegrini Add this Javascript to Q2

Qualtrics.SurveyEngine.addOnload(function()
{
var Q1 = '${q://QID1/ChoiceGroup/SelectedChoices}';
if ( Q1== 'Spain'){
this.setChoiceValueByRecodeValue(1,'true');}
if ( Q1== 'Germany'){
this.setChoiceValueByRecodeValue(2,'true');}
if ( Q1== 'Sweden'){
this.setChoiceValueByRecodeValue(3,'true');}
});

Change the QID and recodevalue 1,2,3 according to your. Let me know if it helps


@MNegrini P/S: Put a pagebrake between Q1 and Q2


Thank you @dxconnamnguyen, works perfectly!


You are right @ArunDubey, the two questions appear on separate pages. Perhaps you have any example of a js I could look to learn how to adapt it to my case? Thank you!

Sorry, I’m working in different time zone. But I’m glad you have already received help from @dxconnamnguyen . All the best!!


Leave a Reply