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

Discussion in 'Javascript' started by babu17, Mar 29, 2006.

  1. babu17

    babu17 Guest

    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.
    babu17, Mar 29, 2006
    #1
    1. Advertising

  2. babu17

    RobG Guest

    babu17 wrote:
    > 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).


    --
    Rob
    RobG, Mar 30, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mit
    Replies:
    1
    Views:
    772
    Ramu Pulipati
    Jan 25, 2006
  2. Victor Kareem

    Working with list box and text boxes

    Victor Kareem, Dec 14, 2003, in forum: C++
    Replies:
    1
    Views:
    375
    Jeff Schwab
    Dec 14, 2003
  3. Stefan Mueller
    Replies:
    5
    Views:
    12,341
    jamesxa
    Jun 16, 2009
  4. yakuza

    check box clear select boxes

    yakuza, Jun 11, 2006, in forum: Javascript
    Replies:
    3
    Views:
    81
    yakuza
    Jun 12, 2006
  5. Daniel

    Count check boxes

    Daniel, Aug 27, 2009, in forum: Javascript
    Replies:
    25
    Views:
    252
    Richard Cornford
    Sep 3, 2009
Loading...

Share This Page