Skip to content

Commit 0f0f48f

Browse files
committed
Implement 10
1 parent 4db2c3b commit 0f0f48f

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,39 @@
9999
</div>
100100

101101
<script>
102+
let checkboxes = document.querySelectorAll("input[type=checkbox]")
103+
let lastCheckedBox
104+
105+
function setLastCheckedBox(checkbox) {
106+
console.log("setLastCheckedBox")
107+
if (checkbox.checked)
108+
lastCheckedBox = checkbox
109+
}
110+
111+
function checkInBetweenBoxes(box1, box2) {
112+
let doCheckBoxes = false
113+
114+
console.log("checkInBetweenBoxes")
115+
checkboxes.forEach(checkbox => {
116+
if (checkbox === box1 || checkbox === box2)
117+
doCheckBoxes = !doCheckBoxes
118+
119+
if (doCheckBoxes)
120+
checkbox.checked = true
121+
})
122+
}
123+
124+
function handleCheck(e) {
125+
console.log(lastCheckedBox)
126+
if (lastCheckedBox && e.shiftKey && this.checked)
127+
checkInBetweenBoxes(this, lastCheckedBox)
128+
129+
setLastCheckedBox(this)
130+
}
131+
132+
checkboxes.forEach(checkbox => {
133+
checkbox.addEventListener('click', handleCheck)
134+
})
102135
</script>
103136
</body>
104137
</html>

0 commit comments

Comments
 (0)