Javascript to pre-select a question answer that is a multi-select in select box format | XM Community
Skip to main content

Hi,
I am trying to pre-select an answer based on a previous answer and have it working, when the second question is in list format and not select box format.
I have done the following javascript on the second question, the one getting preloaded:
'''
Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/
var Instructor = "${q://QID4/SelectedChoicesRecode}";
if(Instructor.includes("57206")) this.setChoiceValueByRecodeValue(15, true);
if(Instructor.includes('80727')) this.setChoiceValueByRecodeValue(21, true);
});
'''
This works and selects the proper choices if I use list format. However, the list is about 200 options long so would really prefer the select box format so that I can use select2 to make it a nice dropdown with search.
Is there something I am overlooking? I looked at the javascript calls and did not see anything specific for the select box format.
Thanks in advance,
Brian

If you are using commands from the Qulatrics Questions API (such as  

this.setChoiceValueByRecodeValue
) then the display format of the question won't matter. You should ideally be getting the same results. Because this is updating the values at the backend.
However, these methods will not work with external libraries such as select2. I think select2 has options for default selection and you'll have to use those.


Hi,
I am using the questions API, and it works in qualtrics on a multi-select question when it is list format, when i change it to selectbox format it does not work, this is before adding the select2 layer. I am trying to get it to just work in qualtrics first, so unless it is being recorded with no visual to the user that the item is selected, the first part of your statement is not holding true for me. I can open the survey, have it work in list format, edit the question to select box format, no other change, hit refresh and it does not work.
Thanks,
Brian


Yes you are right. I just checked. It works for MC single answer, but not for MC multiple answer.
You'll probably need to get in touch with the support team to figure this out, because it seems like a limitation/bug from the backend.


So it does work for multi-choice too just only in list view, not multi-select view.


Leave a Reply