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.
29830 questions
5148
votes
68 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
  • 58,881
  • 64
  • 151
  • 199
4554
votes
44 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
  • 56,100
  • 19
  • 68
  • 100
1476
votes
27 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
  • 25,479
  • 31
  • 107
  • 168
1180
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
  • 88,262
  • 77
  • 290
  • 428
1061
votes
43 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
  • 12,007
  • 9
  • 36
  • 47
978
votes
48 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
  • 36,743
  • 36
  • 104
  • 127
811
votes
13 answers

Check/Uncheck checkbox with JavaScript

How can a checkbox be checked/unchecked using JavaScript?
lisovaccaro
  • 32,502
  • 98
  • 258
  • 410
704
votes
21 answers

Get checkbox value in jQuery

How can I get a checkbox's value in jQuery?
maztt
  • 12,278
  • 21
  • 78
  • 153
697
votes
21 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
  • 8,850
  • 8
  • 38
  • 54
636
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
  • 6,379
  • 2
  • 13
  • 5
597
votes
21 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
  • 44,985
  • 76
  • 186
  • 285
519
votes
11 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
  • 9,697
  • 21
  • 68
  • 103
481
votes
10 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
  • 28,032
  • 17
  • 85
  • 106
433
votes
24 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
  • 108,152
  • 195
  • 629
  • 1,012
374
votes
17 answers

Cypress: Test if element does not exist

I want to be able to click on a check box and test that an element is no longer in the DOM in Cypress. Can someone suggest how you do it? // This is the Test when the checkbox is clicked and the element is…
Maccurt
  • 12,655
  • 7
  • 32
  • 43
1
2 3
99 100