Questions tagged [checkbox]

A checkbox is a graphical user interface element that permits the user to make a binary selection.

A checkbox is a graphical user interface element that permits the user to make a binary selection. Checkboxes are often shown on the screen as a square box that can contain white space (for false) or a tick mark or X (for true). A caption describing the meaning of the checkbox is normally shown adjacent to the checkbox. Inverting the state of a checkbox is done by clicking the mouse on the box, or the caption, or by using a keyboard shortcut, such as the space bar.

Source: http://en.wikipedia.org/wiki/Checkbox


Some applications optionally allow a third state of Null, usually indicated by a grayed-out appearance. A similar provision is often made for a new record which has no instantiated values.

Here is an example of HTML code to present a checkbox in a user-entry form:

<input type="checkbox" name="example" value="foo">foo
  • The checked attribute is a boolean attribute.
  • When present, it specifies that an element should be pre-selected (checked) when the page loads.
  • The checked attribute can be used with <input type="checkbox"> and <input type="radio">.
  • The checked attribute can also be set after the page load, with a JavaScript.
28124 questions
4831
votes
67 answers

How do I check whether a checkbox is checked in jQuery?

I need to check the checked property of a checkbox and perform an action based on the checked property using jQuery. For example, if the age checkbox is checked, then I need to show a textbox to enter age, else hide the textbox. But the following…
Prasad
  • 56,343
  • 61
  • 142
  • 199
4301
votes
42 answers

Setting "checked" for a checkbox with jQuery

I'd like to do something like this to tick a checkbox using jQuery: $(".myCheckBox").checked(true); or $(".myCheckBox").selected(true); Does such a thing exist?
tpower
  • 53,004
  • 18
  • 65
  • 99
1316
votes
25 answers

Check if checkbox is checked with jQuery

How can I check if a checkbox in a checkbox array is checked using the id of the checkbox array? I am using the following code, but it always returns the count of checked checkboxes regardless of id. function isCheckedById(id) { alert(id); …
Jake
  • 22,811
  • 27
  • 96
  • 154
1087
votes
12 answers

How to create a checkbox with a clickable label?

How can I create an HTML checkbox with a label that is clickable (this means that clicking on the label turns the checkbox on/off)?
laurent
  • 79,308
  • 64
  • 256
  • 389
919
votes
36 answers

How to style a checkbox using CSS

I am trying to style a checkbox using the following: But the style is not applied. The checkbox still displays its default style. How do I give it the…
Salman Virk
  • 10,525
  • 8
  • 31
  • 44
878
votes
46 answers

Can HTML checkboxes be set to readonly?

I thought they could be, but as I'm not putting my money where my mouth was (so to speak) setting the readonly attribute doesn't actually seem to do anything. I'd rather not use Disabled, since I want the checked check boxes to be submitted with the…
Electrons_Ahoy
  • 30,983
  • 34
  • 101
  • 126
633
votes
12 answers

Check/Uncheck checkbox with JavaScript

How can a checkbox be checked/unchecked using JavaScript?
lisovaccaro
  • 27,544
  • 92
  • 235
  • 388
626
votes
20 answers

jQuery checkbox change and click event

$(document).ready(function() { //set initial state. $('#textbox1').val($(this).is(':checked')); $('#checkbox1').change(function() { $('#textbox1').val($(this).is(':checked')); }); $('#checkbox1').click(function() { if…
Professor Chaos
  • 7,900
  • 7
  • 33
  • 52
607
votes
18 answers

Get checkbox value in jQuery

How can I get a checkbox's value in jQuery?
maztt
  • 11,509
  • 19
  • 73
  • 147
596
votes
20 answers

Testing if a checkbox is checked with jQuery

If the checkbox is checked, then I only need to get the value as 1; otherwise, I need to get it as 0. How do I do this using jQuery? $("#ans").val() will always give me one right in this case:
Rajeev
  • 39,163
  • 71
  • 171
  • 269
544
votes
19 answers

jQuery set checkbox checked

I already tried all the possible ways, but I still didn't get it working. I have a modal window with a checkbox I want that when the modal opens, the checkbox check or uncheck should be based on a database value. (I have that already working with…
psopa
  • 5,459
  • 2
  • 11
  • 5
463
votes
7 answers

jQuery if checkbox is checked

I have a function below that I want to only trigger when a checkbox in the same tr is checked. Please tell me what I am doing wrong, the usual methods are not working. Thanks JS $(".add_menu_item_table").live('click', function() { var value_td =…
Clinton Green
  • 8,667
  • 15
  • 60
  • 101
454
votes
9 answers

What's the proper value for a checked attribute of an HTML checkbox?

We all know how to form a checkbox input in HTML: What I don't know -- what's the technically correct value for a checked checkbox? I've seen these all work:
buley
  • 24,595
  • 17
  • 76
  • 99
417
votes
23 answers

Toggle Checkboxes on/off

I have the following: $(document).ready(function() { $("#select-all-teammembers").click(function() { $("input[name=recipients\\[\\]]").attr('checked', true); }); }); I'd like the id="select-all-teammembers" when…
AnApprentice
  • 97,752
  • 174
  • 583
  • 971
331
votes
42 answers

POST unchecked HTML checkboxes

I've got a load of checkboxes that are checked by default. My users will probably uncheck a few (if any) of the checkboxes and leave the rest checked. Is there any way to make the form POST the checkboxes that are not checked, rather than the ones…
reach4thelasers
  • 23,986
  • 21
  • 87
  • 119
1
2 3
99 100