3
I’m creating checkboxes from the comic book. I have another one that defines whether all the other checkboxes are checked or not. When I run the first time it works well, but the second time it doesn’t.
HTML
<div class="row smart-form">
<section class="col col-3">
<div class="checkbox">
<label>
<input type="checkbox" name="selectAll" id="check0" class="checkbox style-0 checkDoc">
<span>Marcar/Desmarcar todos</span>
</label>
</div>
</section>
</div>
<div class="row smart-form">
@for(dt <- docTipo) {
<section class="col col-3">
<div class="checkbox">
<label>
<input type="checkbox" name="docTipo" id="[email protected]" class="checkbox style-0">
<span>@dt.descricao</span>
</label>
</div>
</section>
}
</div>
JQUERY
$(document).on('change','.checkDoc', function() {
if(this.checked) {
$("input[name=docTipo]").attr("checked", true);
$("input[name=docTipo]").attr("disabled", true);
} else {
$("input[name=docTipo]").attr("checked", false);
$("input[name=docTipo]").attr("disabled", false);
}
});
At the first click on the checkbox, all the others are selected and disabled, at the second click everything is downgraded and enabled, at the third click they are disabled but not marked. I have already inspected element, and it is added the checked in each one but in the browser does not appear the visa :s
Inspect Elemento
Any suggestions?
Can you put the rendered HTML? and if possible join a jsFiddle?
– Sergio
I’ve never done jsFiddle :s And the checkboxes are being created from the BD, I think the problem of not working might come from there.
– Hugo Machado
Ok, no problem. Then merge the HTML that appears on the client/browser side.
– Sergio
I think that’s what you want to see, sorry but I’m new at this :)
– Hugo Machado