Skip to content

Commit 88b1672

Browse files
Nikki ByrneNikki Byrne
authored andcommitted
code added for checkboxes
1 parent e53a16c commit 88b1672

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

10 - Hold Shift and Check Checkboxes/index-START.html

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
html {
1111
font-family: sans-serif;
12-
background:#ffc600;
12+
//background:#ffc600;
1313
}
1414

1515
.inbox {
@@ -99,6 +99,37 @@
9999
</div>
100100

101101
<script>
102+
// Check if they had the shift key down
103+
// AND check that they are checking it
104+
105+
const checkboxes = document.querySelectorAll('.inbox input[type="checkbox"');
106+
let lastChecked;
107+
108+
109+
function checkedInput(e){
110+
let inBetween = false;
111+
if (e.shiftKey && this.checked) {
112+
//console.log('this has been checked');
113+
checkboxes.forEach(checkbox => {
114+
console.log(checkbox);
115+
if(checkbox === this || checkbox === lastChecked) {
116+
inBetween = !inBetween;
117+
console.log('this is last');
118+
}
119+
if(inBetween) {
120+
checkbox.checked = true;
121+
}
122+
123+
});
124+
}
125+
lastChecked = this;
126+
}
127+
128+
checkboxes.forEach(function(checkbox) {
129+
checkbox.addEventListener('click', checkedInput);
130+
});
131+
132+
102133
</script>
103134
</body>
104135
</html>

0 commit comments

Comments
 (0)