0

Help me i keep getting an error. I want to get the total amount of checkboxes and subtract specified amount when unchecked.

https://code.sololearn.com/Wl10czAcnNso/?ref=app

18th Mar 2018, 7:19 AM
Wilfred Florendo
Wilfred Florendo - avatar
3 Antworten
+ 3
To avoid this kind of pseudo-index error (by appending indexes to id names), better practice would be to set to each of your checkbox group to be used in your loop a shared class name, then select them with document.getElementsByClassName('name_of_the_shared_class'), and iterate over the returned array-like... Another smart way of selecting elements is to use document.querySelectorAll(/*string with css selector format*/) ;)
18th Mar 2018, 9:49 AM
visph
visph - avatar
+ 2
You don't have an input with the id of tapsi2 and your for loop is wrong as it attempts to use i from 0 to 18. Easiest fix is to change tapsi1 to tapsi2 and then change i in your for loop to start at 2 and the condition to go until i<20. This seems to get it working. edit: it looks like you do have a tapsi0, missed this at first look, so you'll need to re-number your inputs correctly and then your for loop should work.
18th Mar 2018, 8:19 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
@ChaoticDawg thankyou so much. You're a big help. I get it now :)
18th Mar 2018, 8:31 AM
Wilfred Florendo
Wilfred Florendo - avatar