I have this code that a button marks and unchecks a checkbox link
Instead of the button in my case it would be a combobox that marks / unchecks checkbox
Could anyone help me? I'm a layman at js ..
I made this code however it marks the option and does not uncheck when I make the change in combobox
<div class="form-group col-xs-8 col-sm-2" th:classappend="${#fields.hasErrors('perfil')} ? has-error">
<label for="perfil" class="control-label">Perfil</label> <select class="form-control" th:field="*{perfil}">
<option data-atendimento="ATENDIMENTO" value="ATENDIMENTO">Atendimento</option>
<option data-diretor="DIRETOR" value="DIRETOR">Diretor</option>
<option data-estoque="ESTOQUE" value="ESTOQUE">Estoque</option>
<option data-gerente="GERENTE" value="GERENTE">Gerente</option>
<option data-ti="TI" value="TI">T.I</option>
<option data-vendedor="VENDEDOR" value="VENDEDOR">Vendedor</option>
</select>
</div>
var select = document.querySelector('select');
select.addEventListener('change', function() {
var selecionada = this.options[this.selectedIndex];
var atendimento = selecionada.getAttribute('data-atendimento');
if (atendimento) {
$('#permissoes3').each(function() {
if (this.checked)
$(this).attr("checked", false);
else
$(this).prop("checked", true);
});
$('#permissoes4').each(function() {
if (this.checked)
$(this).attr("checked", false);
else
$(this).prop("checked", true);
});
$('#permissoes6').each(function() {
if (this.checked)
$(this).attr("checked", false);
else
$(this).prop("checked", true);
});
var select = document.querySelector('select');
select.addEventListener('change', function() {
var selecionada = this.options[this.selectedIndex];
var diretor = selecionada.getAttribute('data-diretor');
if (diretor) {
$('#permissoes1').each(function() {
if (this.checked)
$(this).attr("checked", false);
else
$(this).prop("checked", true);
});
$('#permissoes3').each(function() {
if (this.checked)
$(this).attr("checked", false);
else
$(this).prop("checked", true);
});
$('#permissoes6').each(function() {
if (this.checked)
$(this).attr("checked", false);
else
$(this).prop("checked", true);
});