JTK
JTK

Reputation: 1519

Uncheck a group of check buttons

I'm trying to uncheck a group of check buttons in an onclick event:

HTML:

 </div>
            <button onclick="getChart(); uncheck();" type="submit" class="btn btn-default" id="refreshChart">Request</button>
        </div>

            <form class="form">
                <div class="btn-group btn-group-justified " data-toggle="buttons" name="chartSelect">
                    <label class="btn btn-info" id ="hide">
                        <input name="hide" type="checkbox" ><span>Hide</span>
                    </label>
                    <label class="btn btn-info">
                        <input name="total" id="total" type="checkbox">Total
                    </label>
                    <label class="btn btn-info">
                        <input name="max" id="max" type="checkbox">Max
                    </label>
                    <label class="btn btn-info">
                        <input name="mean" id="mean" type="checkbox">Mean
                    </label>
                    <label class="btn btn-info">
                        <input name="min" id="min" type="checkbox">Min
                    </label>
                    <label class="btn btn-info">
                        <input name="extrapo" id="extrapolation" type="checkbox">Extrapo
                    </label>
                    <label class="btn btn-info">
                        <input name="all" id="all" type="checkbox">All
                    </label>
                </div>
            </form>

I'm even just trying to just get one button to uncheck with no success.

JS:

function uncheck() {
    if ($('[name=max]').is(':checked')) {
        $('[name=max]').attr('checked', false);
    }
}

Upvotes: 0

Views: 51

Answers (2)

TheVillageIdiot
TheVillageIdiot

Reputation: 40537

It seems that calling filter is like this:

$("div[data-toggle='buttons'] input[type='checkbox']").is(":checked")

does not work. But if you put it with selector, it works. So this is fine:

$("div[data-toggle='buttons'] input[type='checkbox']:checked")

Now you can uncheck them all:

$("div[data-toggle='buttons'] input[type='checkbox']:checked").removeAttr("checked");

Try it in this fiddle

Upvotes: 1

Jonathan.Brink
Jonathan.Brink

Reputation: 25443

It looks like your code is working except that you have a call to a function getChart() that is not defined. When I remove that function call the checkbox is unchecked when clicking the button.

https://jsbin.com/yakiyopoye/edit?html,output

Upvotes: 0

Related Questions