6

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?

nalply
  • 26,770
  • 15
  • 78
  • 101
Jason94
  • 13,320
  • 37
  • 106
  • 184

6 Answers6

21

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;

Community
  • 1
  • 1
Arrabi
  • 3,718
  • 4
  • 26
  • 38
  • 1
    i tried you code but it doesn't work unless i write like : `document.getElementById("ckBox").checked = true` and not like `document.getElementById("ckBox").checked = 'true'` – Fabio Delarias Nov 03 '13 at 08:24
13

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

pixelbobby
  • 4,368
  • 5
  • 29
  • 49
2

plese see this post

also note that in jquery 1.6 you should use

$(".mycheckbox").prop("checked", true/false)
Community
  • 1
  • 1
mcgrailm
  • 17,469
  • 22
  • 83
  • 129
1

Check it:

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

Uncheck it:

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

Adjust selector accordingly.

Rob Cowie
  • 22,259
  • 6
  • 62
  • 56
1

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

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

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

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

josh.trow
  • 4,861
  • 20
  • 31
  • sorry- no. this is not correct. that selector will not work, you cannot access the `checked` property like that, nor is it conventional to call the `click()` event of the checkbox to uncheck it. Also, the correct function is `removeAttr()` Please read [jQuery API](http://api.jquery.com/category/attributes/) before posting. – pixelbobby May 12 '11 at 13:58