1
I have the following code:
<div class="form-group">
<label><input type="checkbox" onclick="marcarTodos(this)" name="Tipo" value="Usuarios"> Usuários:</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="Usuarios" value="Incluir"> Incluir
</label>
<label>
<input type="checkbox" name="Usuarios" value="Alterar"> Alterar
</label>
<label>
<input type="checkbox" name="Usuarios" value="Excluir"> Excluir
</label>
<label>
<input type="checkbox" name="Usuarios" value="Consultar"> Consultar
</label>
<label>
<input type="checkbox" name="Usuarios" value="Autorizar"> Autorizar
</label>
</div>
<hr>
<div class="form-group" >
<label><input type="checkbox" onclick="marcarTodos(this)" name="Tipo" value="Segmento"> Segmento:</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="Segmento" value="Incluir"> Incluir
</label>
<label>
<input type="checkbox" name="Segmento" value="Alterar"> Alterar
</label>
<label>
<input type="checkbox" name="Segmento" value="Excluir"> Excluir
</label>
<label>
<input type="checkbox" name="Segmento" value="Consultar"> Consultar
</label>
</div>
<hr>
<div class="form-group" >
<label><input type="checkbox" onclick="marcarTodos(this)" name="Tipo" value="Setor"> Setor:</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="Setor" value="Incluir"> Incluir
</label>
<label>
<input type="checkbox" name="Setor" value="Alterar"> Alterar
</label>
<label>
<input type="checkbox" name="Setor" value="Excluir"> Excluir
</label>
<label>
<input type="checkbox" name="Setor" value="Consultar"> Consultar
</label>
</div>
And with that I have the following result:
The goal is to mark a checkbox, it marks all, but I would like the checkboxes to be disabled and only disabled when clicking a checkbox (Users, Segments, Industry).
The jquery code is this:
<script type="text/javascript">
function marcarTodos(radio) {
const itens = document.querySelectorAll(`[name$=${radio.value}]`);
for(item of itens) {
item.checked = radio.checked;
}
}
</script>
I saw that you have that code, but did not know how to apply within my solution.
It was not very clear what your goal was (the sentence got confused), could you clarify it better? More specifically the phrase: "would like checkboxs to be disabled and only disabled by clicking on a checkbox". There is no way to know if you want "parent" checkboxes to activate/deactivate the "kids" groups, or if they mark/unmark all "kids".
– fernandosavio