1

There are two separate divs: check_one & check_two. check_one has 4 boxes in it, check_two has 1.

If you check the checkbox within the check_two div, it should uncheck all chekced boxes within the first div, check_one. That's sort of confusing, but that is what I'm attempting to do.

HTML ::

<div id="check_one">
    <label>Stuff 1</label> <input name="" type="checkbox" value="" id="group1" checked="checked"><br>
    <label>Stuff 2</label> <input name="" type="checkbox" value="" id="group1" checked="checked"><br>
    <label>Stuff 3</label> <input name="" type="checkbox" value="" id="group1" checked="checked"><br>
    <label>Stuff 4</label> <input name="" type="checkbox" value="" id="group1" checked="checked">
</div>
<br>
<div id="check_two">
    <label>Undo</label> <input name="uncheckMe" type="checkbox" value="" id="group2">
</div>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

jQuery ::

$('input[name=uncheckMe]').change(
{
    var checked = $("#group1").attr("checked");

    if(checked)
    {
        $("#check_two").attr("disabled", true);
    }

});​
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Rav
  • 13
  • 3
  • Next time, close your
    and id is a UNIQUE identifier throughout your html page, so your "group1" id violates this rule.
    – JofryHS Nov 29 '12 at 00:35
  • Also, you have to put quote after your attr selector: $('input[name="uncheckMe"]').change() – JofryHS Nov 29 '12 at 00:36
  • @JofryHS:
    isn't recommended for HTML.
    is fine. See http://stackoverflow.com/a/1946452/462117
    – nandhp Nov 29 '12 at 00:50

2 Answers2

0

Try this:

$("input[name='uncheckMe']").change(function(){
    if ($(this).is(":checked")){       
        $("#check_one input").removeAttr("checked");
    }
});

And a jsFiddle: http://jsfiddle.net/PgHbu/3/

Alex Kawrykow
  • 95
  • 1
  • 1
  • 3
0

I created a jsFiddle for this http://jsfiddle.net/Twisty/ta2qT/

You're missing a Function within Change():

    $('input[name=uncheckMe]').change(function(){
        $("#check_one > input").each(function(i) {
            if ($(this).is(":checked")) {
                $(this).removeAttr("checked");
            }
        });
    });
Twisty
  • 30,304
  • 2
  • 26
  • 45