-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathList of answered and unanswered questions.js
46 lines (43 loc) · 1.43 KB
/
List of answered and unanswered questions.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
41
42
43
44
45
46
Qualtrics.SurveyEngine.addOnReady(function () {
document.querySelector("#NextButton").onclick = function () {
let page_ans = [],
page_uans = [];
document.querySelectorAll("div[id^=QID][class*=QID]").forEach((question) => {
let chosen = question.querySelectorAll(".q-checked");
if (chosen.length == 0) {
page_uans.push(question.id);
} else if (chosen.length > 0) {
page_ans.push(question.id);
}
});
let old_ans = String(Qualtrics.SurveyEngine.getEmbeddedData("answered"))
.split(",")
.filter((el, ind, ar) => {
if (ar.indexOf(el) != ind || el == "null") return false;
else return el;
});
let old_uans = String(Qualtrics.SurveyEngine.getEmbeddedData("unanswered"))
.split(",")
.filter((el, ind, ar) => {
if (ar.indexOf(el) != ind || el == "null") return false;
else return el;
});
page_ans.forEach((item) => old_ans.push(item));
page_uans.forEach((item) => old_uans.push(item));
old_uans = old_uans
.filter((a) => {
if (old_ans.indexOf(a) > -1) return false;
else return a;
})
.filter((el, ind, ar) => {
if (ar.indexOf(el) != ind || el == "null") return false;
else return el;
});
old_ans = old_ans.filter((el, ind, ar) => {
if (ar.indexOf(el) != ind || el == "null") return false;
else return el;
});
Qualtrics.SurveyEngine.setEmbeddedData("unanswered", old_uans.join());
Qualtrics.SurveyEngine.setEmbeddedData("answered", old_ans.join());
};
});