0

I have a table of checkboxes. At the top is an Administrator box, then below a bunch of other permissions. If the Admin box is checked all other boxes should be checked, and if another box is unchecked then the Admin box should uncheck. I have it working on the initial click but if you click the Admin box it checks all others, then uncheck an other option it unchecks the Admin. Check the Admin a second time and nothing happens.

http://jsfiddle.net/HCpQg/1/

$("#administrator").click(function(){
if ($(this).is(':checked')) {
    $('.permissions').attr('checked',true);
}
});

$(".permissions").click(function(){
if ($(this).is(':checked')) {
} else {
$('#administrator').attr('checked',false);
}
});

2 Answers 2

2

Use .prop() as opposed to .attr().

http://api.jquery.com/prop/

Sign up to request clarification or add additional context in comments.

Comments

0

Just my 2 cents: if you use uniform styling:

$(function () {
    $(":checkbox").uniform();
});

then you will need to call

$.uniform.update();

after you dynamically check/uncheck checkbox. I've just spent 6 hours trying until I dug up this bit...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.