Using Javascript in Qualtrics for display logic when answers are associated with hidden choices? | XM Community
Skip to main content
I have an Excel file setup with two columns. Column A, countries, Column B, their associated demonyms, 1 per 1. What I want to do is ask questions about which country a person is born in, then their current country of residence, citizenship, etc. On a subsequent question, I would like to ask them for their agreement on a Likert scale ("I am [demonym]"). I want to show the demonym associated with each of the countries the respondent chooses. For example, if someone says they were born in Mexico but currently live in the US and are an American citizen, I want to ask them in a Matrix style question "I am [Mexican]" and "I am [American]." I know how to do this via display logic: I would say "Display Mexican if Mexico is selected for place of birth, place of current residence, or place of citizenship," and I would do the same for "American." The problem is, I have over 190 countries so this is a lot of display logic to add for each demonym response choice. How can I link the countries to their demonyms in Qualtrics and display the demonyms associated with the appropriate country responses that the respondent has made? Is there a way to do this via JavaScript? (Never coded before.)
See this post:

https://www.qualtrics.com/community/discussion/comment/15688#Comment_15688
Thank you so very much, TomG!



I think I understand. I'm to list all the demonyms next to the countries within the same answer choices but hide them using that code. That way, they will be choosing the demonym associated with the country at the same time. Then I can pipe in their choices into the next question and this time, hide the countries with the code and show the demonyms. I'm unsure if the code goes into the "Add JavaScript" section of the overall question or if I write it directly into the answer choice itself, but I'll play around and try both.



One quick additional question: with what question type can I do this? I currently have Drill Downs for the country choice questions, which I don't think allows for this. I hate to do Single or Multiple Answer Multiple Choice question types because they look bad to respondents, so if not the Drill Downs, I would prefer Dropdown Lists (Multiple Choice question type), Select Boxes (Multiple Choice question type) or Likert or Profile Drop Down Lists (Matrix Table question types). Would the method you described work on any of those?
> @ResearchPsychologist said:

> I think I understand. I'm to list all the demonyms next to the countries within the same answer choices but hide them using that code. That way, they will be choosing the demonym associated with the country at the same time. Then I can pipe in their choices into the next question and this time, hide the countries with the code and show the demonyms.

Correct.

> I'm unsure if the code goes into the "Add JavaScript" section of the overall question or if I write it directly into the answer choice itself, but I'll play around and try both.

Code goes in "Add JavaScript" in the addOnload function.

> One quick additional question: with what question type can I do this? I currently have Drill Downs for the country choice questions, which I don't think allows for this. I hate to do Single or Multiple Answer Multiple Choice question types because they look bad to respondents, so if not the Drill Downs, I would prefer Dropdown Lists (Multiple Choice question type), Select Boxes (Multiple Choice question type) or Likert or Profile Drop Down Lists (Matrix Table question types). Would the method you described work on any of those?

I haven't tried it on those various types. However, it should work just like any other piped choice. For a drill down, if you build the html into the csv you upload I think it would work although getting the quotes in the html correctly may be tricky.
I got it. Thanks so much, TomG!

Leave a Reply