Jason94
Jason94

Reputation: 13620

How do I uncheck a checkbox?

I have a checkbox that is always checked, but base on user input elsewhere in my form (I have a onChange="functionName" on a select box) I would like to uncheck it.

How do I do that?

Upvotes: 6

Views: 32751

Answers (6)

Arrabi
Arrabi

Reputation: 3778

does it need to be done with jQuery ? what about JavaScript please try this:

Check: document.getElementById("ckBox").checked = true;

UnCheck: document.getElementById("ckBox").checked = false;

Upvotes: 21

user736619
user736619

Reputation:

You just needs to remove the attribute checked from the element.

$("#yourSelect").change(function () {
    $("#yourCheckBox").removeAttr("checked");
});

Upvotes: 1

mcgrailm
mcgrailm

Reputation: 17638

plese see this post

also note that in jquery 1.6 you should use

$(".mycheckbox").prop("checked", true/false)

Upvotes: 2

Rob Cowie
Rob Cowie

Reputation: 22619

Check it:

$('input[name=foo]').attr('checked', true);

Uncheck it:

$('input[name=foo]').attr('checked', false);

Adjust selector accordingly.

Upvotes: 1

josh.trow
josh.trow

Reputation: 4901

I suppose the easiest method is to call $('theCheckbox').click()

You could also use $('theCheckbox').checked = false, or $('theCheckbox').removeAttribute('checked')

Upvotes: -1

pixelbobby
pixelbobby

Reputation: 4440

$('#mycheckbox').attr('checked', false)

Upvotes: 13

Related Questions