I’m trying to write a jQuery script (I have never written one before and I need help). The details are as following; I have a form with check-boxes. Each check-box has a different id and name which I will need for my own programming reasons. What I simply want is to count the number of check-boxes and simply display it on the right side in a fixed div. The div must only be shown after the first checkbox is ticked. How can I do this? My example check-box is :
<input type="checkbox" name="check_box_no_2" id="check_box_no_2" value="some_important_value">
The check-box name is incremental. Meaning the next one will be check_box_no_3. Please help…
So far I have been fiddling with
$("input[type=checkbox][checked]").each(
function() {
// Insert code here
}
);
but this seems not to be working with FireFox.
To select checked checkboxes, you need the
:checkedpsuedo-class. You also need to observe each checkbox, and when its setting changes, update the count and show or hide the div. Here’s one way to do that:Where
#countis the element that will show the count (perhaps a paragraph tag), and#statusis the div you want to show/hide.Full HTML example, for reference: