I have a form and want to find, how many checkboxes have been checked?
My Checkbox id will be same, event_id
and name will be something like this: data[Noncompetitor][is_black][4]
How can i?
Let me know ASAP.
Thanks !
I have a form and want to find, how many checkboxes have been checked?
My Checkbox id will be same, event_id
and name will be something like this: data[Noncompetitor][is_black][4]
How can i?
Let me know ASAP.
Thanks !
Once you have a reference to your form's element, it's easy to loop through the elements:
There are lots of ways to get a reference to the form element. For instance, give the form an
id
and usedocument.getElementById
.So if your form's
id
is "foo", for instance, then:Off-topic: A lot of this stuff can be made a lot easier using a library like jQuery, Prototype, YUI, Closure, or any of several others to smooth over browser differences, give you rich ways to traverse to elements via CSS selectors, and such.
For example, the above can be written using jQuery like this:
...which says, 'find all checked checkboxes that are descendants of the elemen twith the
id
"foo"' and then uses the length of the resulting jQuery object (jQuery objects are array-like).You can use the below code to get the number of check box checked.