-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathHighlight Selected Choices.js
40 lines (34 loc) · 1.71 KB
/
Highlight Selected Choices.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
Qualtrics.SurveyEngine.addOnReady(function () {
const qid = this.questionId;
const all_choices = Qualtrics.SurveyEngine.registry[qid].getChoices();
const base_colours = [
"rgba(238, 50, 70, 0.3)",
"rgba(245, 150, 30, 0.3)",
"rgba(255, 203, 8, 0.3)",
"rgba(178, 210, 53, 0.3",
"rgba(0, 165, 81, 0.3)",
];
// Sets the desired colours initially
all_choices.forEach((item,index) => {
document.querySelector("#" + qid + "-" + item + "-label").style.background = base_colours[index];
document.querySelector("#" + qid + "-" + item + "-label").style.color = "#525252";
});
// Check if anyone clicks on the question
this.questionclick = function(){
// Get the currently selected choices
var selected_choices = this.getSelectedChoices();
// Restore all the colours to their original state
// This is done, so that the options appear the same in case someone unselects a choice
all_choices.forEach((item,index) => {
document.querySelector("#" + qid + "-" + item + "-label").style.background = base_colours[index];
document.querySelector("#" + qid + "-" + item + "-label").style.color = "#525252";
});
// Give a different colour to the selected choices
// background is for the Box and color is for the text
// Change as desired
selected_choices.forEach((item) => {
document.querySelector("#" + qid + "-" + item + "-label").style.background = "DarkBlue";
document.querySelector("#" + qid + "-" + item + "-label").style.color = "Yellow";
});
}
});