-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathOther box validation.js
43 lines (39 loc) · 1.41 KB
/
Other box validation.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
//Other Box Validation -->
Qualtrics.SurveyEngine.addOnReady(function () {
function check_box_and_text() {
setTimeout(() => {
ip_choices.forEach((box) => {
let sel = box.querySelector(".q-checked"),
val = box.querySelector(".InputText").value.trim();
if (sel !== null && val !== "") {
box.querySelector(".InputText").placeholder = "Please enter a value";
nb.disabled = false;
} else if (sel !== null && val === "") {
box.querySelector(".InputText").placeholder = "Please enter a value";
nb.disabled = true;
} else if (sel === null && val !== "") {
box.querySelector(".InputText").placeholder = "";
nb.disabled = true;
box.querySelector(".InputText").value = "";
} else if (sel === null && val === "") {
box.querySelector(".InputText").placeholder = "";
nb.disabled = false;
}
});
}, 200);
}
let ip_box = document.querySelectorAll(".InputText"),
ip_choices = [],
nb = document.querySelector("#NextButton");
if (ip_box.length > 0) {
ip_box.forEach((box) => {
let is_valid = box.parentElement.parentElement.querySelector(".q-checkbox, .q-radio");
if (is_valid) ip_choices.push(is_valid.parentElement);
});
let all_options = document.querySelectorAll(".q-checkbox, .q-radio");
all_options.forEach((opt) => {
opt.parentElement.onclick = check_box_and_text;
});
ip_box.forEach((box) => (box.oninput = check_box_and_text));
}
});