Hi,
Have a question where I am trying to use a simple javascript on the question like:
this.setChoiceValueByRecodeValue(1,true)
This works for me when the question is a single select.
This works for me when it is a multi-select but using list view.
It fails with no error report is it is a multi-select with listbox view. Does anyone have this working in that setup at all? Seems like a potential platform bug to me.
The list is a couple hundred options long so I can't just switch to list view to solve it.
Thanks!
Use browser JS to make these selections. Get the container using the selector
select.
Then set the
selectedattribute of each option that you want selected to
true.
See this demo.
Hmm. This seems close. Two questions.
- I was planning to use the recode values for the selection, this seems to be based on the specific option being shown on the computed out, am I wrong there?
- This is almost too complicated, I would be selecting a single choice coming from an embedded data field, how I can I get rid of all the while's and just set the selection to the embedded data value which should match one of the recode values.
Thanks so much!
Can't comment on either till I see your code. The while's in my code exists to avoid duplication due to randomization.
Hey Brian F,
I think this is what you're looking for... I named my ED field "preSelectRecodeValue" , but you can change it to yours. I also added some checks like if there is no ED value, or if the ED value does not match a recode in the Choice List.
Qualtrics.SurveyEngine.addOnReady(function () {
let quest = this;
let qid = this.questionId;
let ed = '${e://Field/preSelectRecodeValue}';
console.log('Embedded Data value = '+ed);
if (ed.length === 0) {
console.log('No value found in ED "preSelectRecodeValue"');
return
}
let recode_to_select = ed;
console.log('Recode = '+recode_to_select)
let choiceIds_to_select = quest.getChoicesFromRecodeValue(recode_to_select);
if (choiceIds_to_select.length === 0) {
console.log('No choice was found with provided recode');
return
}
console.log(choiceIds_to_select.length.toString()+' choice(s) found with provided recode');
choiceIds_to_select.forEach((choiceId_to_select) => {
let option_to_select = quest.questionContainer.querySelector("#QR\\\\~"+qid+"\\\\~"+choiceId_to_select);
console.log('Option element to select:',option_to_select);
option_to_select.selected = true;
});
});
https://www.qualtrics.com/community/discussion/comment/36852#Comment_36852This was exactly what i was looking to do!!!
Thank you so much!
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.