-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
214 lines (166 loc) · 6.72 KB
/
script.js
File metadata and controls
214 lines (166 loc) · 6.72 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
let first = document.querySelector('#BurgerSer');
let second = document.querySelector('#beconnummer');
let third = document.querySelector('#Protocolnummer');
function toggleDisabled(input) {
let inputs = [first, second, third];
if (input.value.trim() !== "") {
inputs.forEach(field => {
if (field !== input) {
field.setAttribute("disabled", "true");
field.style.backgroundColor = "#d0d0d0";
field.style.border= ".1em solid #a9a9a9";
// field.style.pla
}
});
} else {
inputs.forEach(field => {
field.removeAttribute("disabled");
field.style.backgroundColor = "";
});
}
}
// Voeg event listeners toe aan elk inputveld
[first, second, third].forEach(input => {
input.addEventListener("input", () => toggleDisabled(input));
});
const form = document.querySelector("form");
const button = form.querySelector("button");
function updateButtonState() {
if (form.checkValidity()) {
button.removeAttribute("disabled");
} else {
button.setAttribute("disabled", "true");
}
}
// Luisteren naar veranderingen in het formulier
form.addEventListener("input", updateButtonState);
form.addEventListener("change", updateButtonState);
// Initialiseren bij pagina-load
updateButtonState();
const form1 = document.getElementById("Form1");
const form2 = document.getElementById("Form2");
// Verberg Form2 bij het laden van de pagina
form2.style.display = "none";
// Voeg een event toe aan Form1 om het te verbergen en Form2 te tonen
form1.onsubmit = function(event) {
event.preventDefault(); // Voorkom standaard verzenden van formulier
form1.style.display = "none"; // Verberg Form1
form2.style.display = "block"; // Toon Form2
};
document.querySelector("#Form2 button").onclick = function(event) {
event.preventDefault(); // Voorkom standaard formuliergedrag
form2.style.display = "none"; // Verberg Form2
form1.style.display = "block"; // Toon Form1
};
// als de checkboxes 1b,1c,1d open zijn dat wil ik bepaalde inputs required maken
// document.addEventListener("DOMContentLoaded", function () {
// const fieldsetB = document.querySelector(".b"); // Selecteer alleen fieldset met class "b"
// const checkbox = fieldsetB.querySelector("#ja"); // De checkbox binnen fieldset "b"
// const input = fieldsetB.querySelectorAll("input:not([type='checkbox'])"); // Alle inputs behalve checkboxes binnen fieldset "b"
// function toggleRequired() {
// if (checkbox.checked) {
// input.forEach(field => field.setAttribute("required", "true"));
// } else {
// input.forEach(field => field.removeAttribute("required"));
// }
// }
// // Event listener toevoegen aan de checkbox
// checkbox.addEventListener("change", toggleRequired);
// });
// const fieldsetB = document.querySelector(".b"); // Selecteer alleen fieldset met class "b"
// const checkbox = fieldsetB.querySelector("#ja"); // De checkbox binnen fieldset "b"
// const radios = document.querySelectorAll(".expandable input");
// checkbox.addEventListener('change', function() {
// if (this.checked) {
// // Als 'Ja' is geselecteerd, maak de inputs onder expandable verplicht
// radios.forEach(input => {
// input.setAttribute("required", "true");
// });
// } else {
// // Als 'Ja' niet is geselecteerd, verwijder het required attribuut
// radios.forEach(input => {
// input.removeAttribute("required");
// });
// }
// });
/////////////// required /////////////////
const checkbox = document.querySelectorAll("[data-requireding]");
let i = 0;
while(i < checkbox.length) {
checkbox[i].addEventListener("change",requireDingen);
i++;
}
function requireDingen(){
let requirePair = this.getAttribute('data-requireding');
const radios = document.querySelectorAll("[data-requireMe="+requirePair+"] input");
if (this.checked) {
radios.forEach(input => {
input.setAttribute("required", "true");
console.log('aan');
});
} else {
radios.forEach(input => {
input.removeAttribute("required");
console.log('uit');
});
}
console.log("hoi");
}
////////////////// progress ////////////////
document.addEventListener("DOMContentLoaded", function () {
document.getElementById("Form1").addEventListener("input", function () {
const form = this;
const progressBar = document.querySelector("progress");
if (form.checkValidity()) {
progressBar.value = 2;
} else {
progressBar.value = 1;
}
});
console.log(this);
});
////////////////
// const inputFields = document.querySelectorAll("input");
// inputFields.forEach((inputField) => {
// if (localStorage.getItem(inputField.id)) {
// inputField.value = localStorage.getItem(inputField.id);
// }
// inputField.addEventListener("input", () => {
// localStorage.setItem(inputField.id, inputField.value);
// });
// });
document.addEventListener("DOMContentLoaded", () => {
// Selecteer alle inputvelden
const inputFields = document.querySelectorAll("input");
inputFields.forEach((inputField) => {
// Verschillende behandeling op basis van het type inputveld
const fieldId = inputField.id;
// Eerst de waarden uit localStorage halen en toewijzen
if (localStorage.getItem(fieldId) !== null) {
if (inputField.type === "radio") {
// Voor radiobuttons, controleer of de waarde overeenkomt
inputField.checked = (localStorage.getItem(fieldId) === inputField.value);
} else if (inputField.type === "date") {
// Voor datumvelden gewoon de waarde toewijzen
inputField.value = localStorage.getItem(fieldId);
} else {
// Voor normale tekstvelden, e-mail, enz.
inputField.value = localStorage.getItem(fieldId);
}
}
// Event listeners toevoegen voor het opslaan van waarden
if (inputField.type === "radio") {
// Voor radiobuttons luisteren naar het change event
inputField.addEventListener("change", () => {
if (inputField.checked) {
localStorage.setItem(fieldId, inputField.value);
}
});
} else {
// Voor andere velden luisteren naar het input event
inputField.addEventListener("input", () => {
localStorage.setItem(fieldId, inputField.value);
});
}
});
});