Skip to main content

Questions tagged [checkbox]

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

Filter by
Sorted by
Tagged with
5195 votes
68 answers
4.9m views

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 ...
4590 votes
44 answers
3.9m views

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's user avatar
  • 56.7k
1501 votes
27 answers
2.7m views

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. ...
Jake's user avatar
  • 26k
1203 votes
12 answers
1.0m views

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's user avatar
  • 89.9k
1078 votes
45 answers
2.4m views

How to style a checkbox using CSS

I am trying to style a checkbox using the following: <input type="checkbox" style="border:2px dotted #00f;display:block;background:#ff0000;" /> But the style is not applied. The ...
Salman Virk's user avatar
  • 12.2k
1015 votes
49 answers
1.2m views

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 ...
860 votes
13 answers
1.8m views

Check/Uncheck checkbox with JavaScript

How can a checkbox be checked/unchecked using JavaScript?
lisovaccaro's user avatar
  • 33.6k
719 votes
21 answers
1.7m views

Get checkbox value in jQuery

How can I get a checkbox's value in jQuery?
maztt's user avatar
  • 12.5k
711 votes
21 answers
1.9m views

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')); }); ...
Professor Chaos's user avatar
649 votes
19 answers
1.3m views

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 ...
psopa's user avatar
  • 6,509
598 votes
21 answers
760k views

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's user avatar
  • 46.2k
531 votes
11 answers
1.4m views

jQuery if checkbox is checked

I have a function below that I want to trigger only when a checkbox in the same tr is checked. $(".add_menu_item_table").live('click', function() { if ($('input.checkbox_check').attr(':checked'))...
Clinton Green's user avatar
486 votes
10 answers
638k views

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

We all know how to form a checkbox input in HTML: <input name="checkbox_name" id="checkbox_id" type="checkbox"> What I don't know -- what's the technically correct value for a checked checkbox?...
buley's user avatar
  • 28.9k
441 votes
24 answers
639k views

Toggle Checkboxes on/off

I have the following: $(document).ready(function() { $("#select-all-teammembers").click(function() { $("input[name=recipients\\[\\]]").attr('checked', true); }); }); ...
AnApprentice's user avatar
408 votes
16 answers
363k views

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 ...
Maccurt's user avatar
  • 13.6k
385 votes
45 answers
516k views

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 ...
reach4thelasers's user avatar
356 votes
18 answers
1.2m views

How can I check if a checkbox is checked?

I am building a mobile web app with jQuery Mobile and I want to check if a checkbox is checked. Here is my code. <script type=text/javascript> function validate(){ if (remember.checked == ...
Steaphann's user avatar
  • 3,649
319 votes
21 answers
1.0m views

How to read if a checkbox is checked in PHP?

How to read if a checkbox is checked in PHP?
Thew's user avatar
  • 15.9k
291 votes
32 answers
168k views

Android - Spacing between CheckBox and text

Is there an easy way to add padding between the checkbox in a CheckBox control, and the associated text? I cannot just add leading spaces, because my label is multi-line. As-is, the text is way too ...
DougW's user avatar
  • 29.6k
287 votes
9 answers
565k views

Get a list of checked checkboxes in a div using jQuery

I want to get a list of names of checkboxes that are selected in a div with certain id. How would I do that using jQuery? E.g., for this div I want to get array ["c_n_0"; "c_n_3"] or a string "c_n_0;...
Juozas Kontvainis's user avatar
281 votes
15 answers
587k views

Angular 2 Checkbox Two Way Data Binding

I´m fairly new to Angular2 and I have a little problem: In my Login-Component-HTML, I have two checkboxes, which I want to bind in two way data-binding to the Login-Component-TypeScript. This is the ...
Junias's user avatar
  • 3,107
279 votes
17 answers
1.3m views

Get the value of checked checkbox?

So I've got code that looks like this: <input class="messageCheckbox" type="checkbox" value="3" name="mailId[]"> <input class="messageCheckbox" type="checkbox" value="1" name="mailId[]"> ...
Matthew 'mandatory' Bryant's user avatar
278 votes
5 answers
845k views

Getting value of HTML Checkbox from onclick/onchange events

<input type="checkbox" onclick="onClickHandler()" onchange="onChangeHandler()" /> From within onClickHandler and/or onChangeHandler, how can I determine what is the new state of the checkbox?
Maxim Gershkovich's user avatar
277 votes
31 answers
846k views

How to implement a "select all" checkbox in HTML?

I have an HTML page with multiple checkboxes. I need one more checkbox by the name "select all". When I select this checkbox all checkboxes in the HTML page must be selected. How can I do this?
user48094's user avatar
  • 10.6k
271 votes
20 answers
610k views

How to set default Checked in checkbox ReactJS?

I'm having trouble to update the checkbox state after it's assigned with default value checked="checked" in React. var rCheck = React.createElement('input', { type: 'checkbox', ...
Yarin Nim's user avatar
  • 3,737
269 votes
19 answers
532k views

Using jquery to get all checked checkboxes with a certain class name

I know I can get all checked checkboxes on a page using this: $('input[type=checkbox]').each(function () { var sThisVal = (this.checked ? $(this).val() : ""); }); But I am now using this on a ...
leora's user avatar
  • 194k
267 votes
5 answers
289k views

jQuery selector for the label of a checkbox

<input type="checkbox" name="filter" id="comedyclubs"/> <label for="comedyclubs">Comedy Clubs</label> If I have a check box with a label describing it, how can I select the label ...
Darwyn's user avatar
  • 4,776
247 votes
22 answers
240k views

How to handle checkboxes in ASP.NET MVC forms?

Caution: This question is over nine years old! Your best option is to search for newer questions, or to search the answers below looking for your specific version of MVC, as many answers here are ...
user avatar
246 votes
14 answers
612k views

How to retrieve checkboxes values in jQuery

How to use jQuery to get the checked checkboxes values, and put it into a textarea immediately? Just like this code: <html> <head> </head> <body> <div id="c_b"&...
lanqy's user avatar
  • 3,021
241 votes
8 answers
232k views

Find all unchecked checkboxes in jQuery

I have a list of checkboxes: <input type="checkbox" name="answer" id="id_1' value="1" /> <input type="checkbox" name="answer" id="...
Gary's user avatar
  • 4,695
240 votes
13 answers
90k views

asp.net mvc: why is Html.CheckBox generating an additional hidden input

I just noticed that Html.CheckBox("foo") generates 2 inputs instead of one, anybody knows why is this so ? <input id="foo" name="foo" type="checkbox" value="true" /> <input name="foo" type="...
Omu's user avatar
  • 70.8k
240 votes
18 answers
330k views

Using the HTML5 "required" attribute for a group of checkboxes?

When using the newer browsers that support HTML5 (FireFox 4 for example); and a form field has the attribute required='required'; and the form field is empty/blank; and the submit button is clicked; ...
Zabba's user avatar
  • 65.1k
233 votes
11 answers
856k views

Javascript checkbox onChange

I have a checkbox in a form and I'd like it to work according to following scenario: if someone checks it, the value of a textfield (totalCost) should be set to 10. then, if I go back and uncheck ...
bikey77's user avatar
  • 6,532
225 votes
13 answers
324k views

Do checkbox inputs only post data if they're checked?

Is it standard behaviour for browsers to only send the checkbox input value data if it is checked upon form submission? And if no value data is supplied, is the default value always "on"? Assuming ...
Mark's user avatar
  • 2,749
211 votes
10 answers
209k views

How to stop event bubbling on checkbox click

I have a checkbox that I want to perform some Ajax action on the click event, however the checkbox is also inside a container with its own click behaviour that I don't want to run when the checkbox is ...
roryf's user avatar
  • 30k
205 votes
9 answers
392k views

React Checkbox not sending onChange

TLDR: Use defaultChecked instead of checked, working jsbin. Trying to setup a simple checkbox that will cross out its label text when it is checked. For some reason handleChange is not getting fired ...
jdarling's user avatar
  • 2,468
200 votes
18 answers
137k views

Tri-state Check box in HTML?

There is no way to have a tri-state check button (yes, no, null) in HTML, right? Are there any simple tricks or work-arounds without having to render the whole thing by oneself?
Pekka's user avatar
  • 447k
195 votes
12 answers
265k views

Custom checkbox image android

Is there an easy way to use a custom image for a checkbox? I'm looking to duplicate the "starred" behavior of gmail. So I want to have a checkbox that, when checked, is a filled in star. And when ...
Falmarri's user avatar
  • 48.4k
192 votes
21 answers
84k views

Change Checkbox value without triggering onCheckChanged

I have setOnCheckedChangeListener implemented for my checkbox Is there a way I can call checkbox.setChecked(false); without triggering the onCheckedChanged
Archie.bpgc's user avatar
182 votes
26 answers
495k views

How to check/uncheck all checkboxes with a button using jQuery?

I am trying to check/uncheck all checkboxes using jQuery. Now by checking/unchecking the parent checkbox all the child checkboxes are getting selected/deselected also with the text of parent checkbox ...
Ravi's user avatar
  • 4,065
179 votes
16 answers
132k views

How to show android checkbox at right side?

By default android checkbox shows text at right side and checkbox at left I want to show checkbox at right side with text at left how do I achieve this?
UMAR-MOBITSOLUTIONS's user avatar
177 votes
5 answers
538k views

Get $_POST from multiple checkboxes

I have 1 form in with multiple checkboxes in it (each with the code): <input type="checkbox" name="check_list" value="<? echo $row['Report ID'] ?>"> Where $row['Report ID'] is a primary ...
James Andrew's user avatar
  • 7,213
171 votes
27 answers
500k views

How to check all checkboxes using jQuery?

I am not expert with jQuery but I have tried to create a little script for my application. I want to check all checkboxes but it isn't working correctly. First I tried to use attr and after that I ...
Ivan's user avatar
  • 5,208
171 votes
18 answers
896k views

html select only one checkbox in a group

So how can I only allow a user to select only one checkbox? I know radio buttons are "ideal", but for my purpose...it's not. I have a field where users need to select either or of the two options, ...
user962449's user avatar
  • 3,833
157 votes
7 answers
318k views

jQuery checkbox event handling

I have the following: <form id="myform"> <input type="checkbox" name="check1" value="check1"> <input type="checkbox" name="check2" value="check2"> </form> How do I use ...
aeq's user avatar
  • 10.5k
154 votes
20 answers
345k views

Angular ReactiveForms: Producing an array of checkbox values?

Given a list of checkboxes bound to the same formControlName, how can I produce an array of checkbox values bound to the formControl, rather than simply true/false? Example: <form [formGroup]="...
marked-down's user avatar
  • 10.3k
148 votes
7 answers
164k views

Checkboxes in web pages – how to make them bigger?

The standard checkboxes rendered in most browsers are quite small and don’t increase in size even when a larger font is used. What is the best, browser-independent way to display larger checkboxes?
Tony the Pony's user avatar
145 votes
12 answers
288k views

How to uncheck checkbox using jQuery Uniform library

I have a problem with unchecking a checkbox. Have a look at my jsFiddle, where I am attempting: $("#check2").attr("checked", true); I use uniform for styling the checkbox and it simply does not ...
DarkLeafyGreen's user avatar
140 votes
16 answers
414k views

Why cannot change checkbox color whatever I do? [duplicate]

I try to style checkbox background color, but it won't change whatever I do. I am using firefox 29 latest. Is there some rule changes in css or may be in the browser? CSS: input[type="checkbox&...
Ari's user avatar
  • 4,869
136 votes
9 answers
212k views

How to set True as default value for BooleanField on Django?

I'm using BooleanField in Django. By default, the checkbox generated by it is unchecked state. I want the state to be checked by default. How do I do that?
Bin Chen's user avatar
  • 62.8k

1
2 3 4 5
600