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!
Pre-selecting choice of question based on previous value in a multi-select listbox format
Best answer by faris
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;
});
});
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
