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

Default choices on a series of multiple choices questions, based on previous answer

  • September 5, 2023
  • 7 replies
  • 251 views

Forum|alt.badge.img+1

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!

Best answer by Nam Nguyen

@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

View original

7 replies

ArunDubey
QPN Level 8 ●●●●●●●●
Forum|alt.badge.img+41
  • QPN Level 8 ●●●●●●●●
  • 589 replies
  • September 5, 2023

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.


Forum|alt.badge.img+1
  • Author
  • 4 replies
  • September 5, 2023

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!


Nam Nguyen
QPN Level 8 ●●●●●●●●
Forum|alt.badge.img+29
  • QPN Level 8 ●●●●●●●●
  • 1091 replies
  • Answer
  • September 5, 2023

@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


Nam Nguyen
QPN Level 8 ●●●●●●●●
Forum|alt.badge.img+29
  • QPN Level 8 ●●●●●●●●
  • 1091 replies
  • September 5, 2023

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


Forum|alt.badge.img+1
  • Author
  • 4 replies
  • September 5, 2023

Thank you @dxconnamnguyen, works perfectly!


ArunDubey
QPN Level 8 ●●●●●●●●
Forum|alt.badge.img+41
  • QPN Level 8 ●●●●●●●●
  • 589 replies
  • September 6, 2023
MNegrini wrote:

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!!


Harmon187
Level 1 ●
Forum|alt.badge.img+2
  • Level 1 ●
  • 4 replies
  • March 13, 2025

What if there is a similar question to this, but the user could select multiple answers for the first question and then multiple answers in the next question should be selected by default?


Leave a Reply