@qually,
You would probably be better off combining Q1-Q3 into one question with Choice Groups. Then you wouldn’t need JavaScript. You could just carry forward the selected choices.
The ‘this.hideChoice is not a function error’ means there is no such thing as a function named hideChoice associated with the ‘this’ object.
You would need to post your JS code to get help with the above error or the selections not being captured.
Thanks so much @TomG ! I think the Choice Groups formatting would not be ideal for the questions I’m asking unfortunately since many of the response options are sort of long. BUT I am very interested in this option for future studies and was not aware of it until now.
Here’s the code ChatGPT suggested I use:
Qualtrics.SurveyEngine.addOnload(function() {
// Debug: Log that the script has started
console.log("Script started");
// Retrieve selected choices from Embedded Data and log them
var selectedQ1 = "${e://Field/SelectedQ1}".split(",");
var selectedQ2 = "${e://Field/SelectedQ2}".split(",");
console.log("Selected Q1: ", selectedQ1);
console.log("Selected Q2: ", selectedQ2);
var allSelected = selectedQ1.concat(selectedQ2);
console.log("All selected choices: ", allSelected);
// Hide all choices initially
var questionId = this.questionId;
var choices = this.getChoices();
choices.forEach((choiceId) => {
this.hideChoice(choiceId);
});
// Attempt to show only the choices that were selected in Q1 and Q2
allSelected.forEach((selectedChoice) => {
var choiceNumber = this.getChoiceByText(selectedChoice);
if (choiceNumber) {
this.showChoice(choiceNumber);
console.log("Showing choice: ", selectedChoice); // Log shown choices
} else {
console.log("Choice not found for text: ", selectedChoice); // Log if a choice is not found
}
});
});
@qually,
ChatGPT isn’t a reliable source for working code. There are a lot of issues with that code, including at least three functions that don’t exist. There is no simple fix.
You could forego JS by using display logic on the choices.