+ 4

Some problems with checkbox

Hi. It is difficult to describe, especially with my English, so I strongly recommend to you just click and understand that something is wrong here. What do I want: - I want the first parameter from the block to be checked and disabled until any other parameter is selected. - and they should be checked and disabled, when we turn off parameters with button "deselect" But in fact my code does not work correctly. If the first parameter becomes active, then via the "deselect" button, it also turns off. If you activate several parameters and turn off the first one, it will become active again and disabled, if you turn off the second parameter from the block. And for some reason, styles don't work and we can't turn off this. Just when we activate the second parameter. hard... ^_^ Sorry. https://code.sololearn.com/WfmkQkoBu36R/#html

3rd Feb 2018, 12:59 PM
Bogdan Saliuk
Bogdan Saliuk - avatar
2 odpowiedzi
+ 7
Well done mate, it's great to see that you have independently solved the case, great code by the way : )
4th Feb 2018, 5:55 AM
Ipang
+ 1
https://code.sololearn.com/W67HR5iD90U6/#html I managed to achieve the desired results. At first, in html I changed the event to onchange (16, 29, 47 lines) And, actually, I rewrote the function to this event (changeDisabled). It was: function changeDisabled(className){ --var source = document.getElementsByClassName(className) --for (var i = 1; i < source.length; i++){ ----if (source[i].checked === true){ ------source[0].disabled = false; ------break; ------} else { ----------source[0].disabled = true; ----------source[0].checked = true; ------} ----} --} It become: function changeDisabled(className){ --var source = document.getElementsByClassName(className); --var sourceCut = Array.from(source).every(check) // bad supports in app ----if (sourceCut === true){ ------source[0].disabled = true; ------source[0].checked = true; ----} else { ------source[0].disabled = false; ----} --} And some changing in deselectAll. Not clear, but working ^_^. It was: function deselectAll(source) { --var checkboxes = document.getElementsByClassName('set'); ----for(var i=0; i < checkboxes.length; i++) { ------if (checkboxes[i].disabled === true) continue; ------checkboxes[i].checked = source.checked ----} --} It become: function deselectAll(source) { --var checkboxes = document.getElementsByClassName('set'); --for(var i=0; i < checkboxes.length; i++) { ----if (i == 0 || i == 4 || i == 10) { ------checkboxes[i].disabled = true; ------checkboxes[i].checked= true; ------continue ----} ----checkboxes[i].checked = source.checked --} }
3rd Feb 2018, 6:30 PM
Bogdan Saliuk
Bogdan Saliuk - avatar