1
I have this code that a button marks and unchecks a checkbox http://jsfiddle.net/H544C/1/
more instead of the button in my case would be a combobox that marks/unchecks checkbox
Could someone help me? I’m a layman at js..
I made this code but it marks the option and does not uncheck when I trade 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);
});
You want to mark an option in the field
select
and click the button, the checked option is no longer selected? Could you explain better what you need? It was not clear.– Jorge.M
I have a select with 5 profiles when selecting select I would like you to mark the checkbox related to that profile and when I changed profile I left what was marked and selected only the permission of that profile
– Joyce SD
perfils are permissions ex: service profile can only see two things, management profile can see everything .. today is manually click one by one to give permission more now with profile would facilitate as automatically it would mark what each profile has access
– Joyce SD
would look exactly like this example http://jsfiddle.net/H544C/1/ only instead of using button would select
– Joyce SD
where this click (button) would be the combo of select with the profiles and the idea is the same of mark/deselect
– Joyce SD
Now it’s clearer. Post the fields that will be marked automatically for me to create an example.
– Jorge.M
Jorge, the fields come from the database I can put an image because it would facilitate you...
– Joyce SD
It is necessary to know how the data comes. It comes with some class related to select options?
– Jorge.M
each data comes with an id has 24 permissions so permissionA comes id=permissionA , permissionB comes id=permissionsb
– Joyce SD
Right, now the next step: How do I know which permissions each select profile has?
– Jorge.M
just make the select mark/uncheck will help me too because I will "fail" the ids as the director permissions have all so will receive the 24 the attendant only has 5 so it will be only a,b,c,d,e
– Joyce SD
Okay, I’ll create an answer.
– Jorge.M
thank you Jorge.
– Joyce SD