how to count number of check boxes in a check box list.

B

babu17

hi,

i have a list of checkboxes, the number of checkboxes is dynamic. All
the checkboxes have same name.
i am trying to get the length of selected checkboxes.
<input type=checkbox name=name1 value=1>
<input type=checkbox name=name1 value=2>
........ get dynamically.

when i try to get the length in javascript like
document.form.name1.length,
it works fine if number of checkboxes selected are more than 1, but not
for 1.

any idea.
thanks.
 
R

RobG

babu17 said:
hi,

i have a list of checkboxes, the number of checkboxes is dynamic. All
the checkboxes have same name.
i am trying to get the length of selected checkboxes.
<input type=checkbox name=name1 value=1>
<input type=checkbox name=name1 value=2>
....... get dynamically.

when i try to get the length in javascript like
document.form.name1.length,
it works fine if number of checkboxes selected are more than 1, but not
for 1.

any idea.

document.getElementsByName('name1').length;

getElementsByName() always returns an HTMLCollection, even if there are no
elements with the specified name (i.e. the length is zero).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top