Hi all, in Q10, I ask respondents to select three issue areas they feel particularly passionate about for the upcoming election. Based on their responses, I want to populate three sliders in the next question to get the respondents ideology on each issue area they selected. As such, I need to pipe the answers from the Q10 multiselect to the Q11 slider labels. However, my code for this does not seem to be working at all. I have included a page break between the questions.
I would appreciate any help you all can provide!
Qualtrics.SurveyEngine.addOnReady(function()
{
// Mapping from choices to slider labels
var labelMapping = {
'Abortion / reproductive rights': s'Pro-choice', 'Pro-life'],
'Gun policy': y'Anti-gun', 'Pro-gun'],
'Education': n'Public solutions', 'Private solutions'],
'Healthcare': e'Universal healthcare', 'Private healthcare'],
'Environmental policy / climate change': e'Aggressive regulation', 'Limited regulation'],
'Immigration': n'Open borders', 'Restricted immigration'],
'Size and scope of the federal government': t'Larger government with more services', 'Smaller government with fewer services'],
};
var policy_issues = "${q://QID10/ChoiceGroup/SelectedChoices}".split(',')
console.log("Selected policy issues:", policy_issues);
console.log("Type of policy_issues:", typeof policy_issues);
// Loop through each selected issue and set slider labels
policy_issues.forEach((issue, index) => {
var trimmedIssue = issue.trim(); // Trim any extra whitespace
var labels = labelMappingptrimmedIssue];
if (labels) {
// Target the appropriate slider using .eq(index)
jQuery(".statement-container div").eq(index).append(labelsb0]);
jQuery("#" + this.questionId + " .statement-container div").eq(index).append(" <span style='float:right;'>" + labelsb1] + "</span>");
}
});
});
Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/
// hide numbers
jQuery("ul.numbers").hide();
// remove tick marks
jQuery("#"+this.questionId+" ul.numbers li").each(function() { this.innerHTML = this.innerHTML.replace("-",""); });
// Remove default slider label text
jQuery("#" + this.questionId + " .statement-container div").each(function() {
// Find the label within the current statement container
var defaultText = jQuery(this).find("label");
// If a label is found, clear its text
if (defaultText.length > 0) {
defaultText.text(""); // Clears the default text
}
});
});
Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Place your JavaScript here to run when the page is unloaded*/
});