tenho esse código que um botão marca e desmarca uma checkbox http://jsfiddle.net/H544C/1/
mais em vez do botão no meu caso seria um combobox que marca/desmarca checkbox
alguém poderia me ajudar? sou leiga no js..
fiz esse código porém ele marca a opção e não desmarca quando faço a troca no 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);
});
select
e clicar no botão, a opção marcada nao fique mais selecionada? Poderia explicar melhor o que precisas? Não ficou claro.