ceri

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Cerni

    ceri

    Hello,
    I have to count used checkboxes.How habe I to do this in an easy way.
    Thank you
  • Michael Winter

    #2
    Re: ceri

    Cerni wrote on 24 Nov 2003:
    [color=blue]
    > Hello,
    > I have to count used checkboxes.How habe I to do this in an easy
    > way. Thank you
    >[/color]

    // Input: The name of the form (the form's name attribute)
    // Output: The number of check boxes that have been ticked
    //
    function countBoxes( form )
    {
    var i, count = 0; elems = document.forms[form].elements;

    // Loop through all controls in a form
    for ( i = 0; i < elems.length; ++i ) {

    // Check that the current control is a checkbox
    if ( 'checkbox' == elems[i].type ) {

    // If it is, and it's checked, increment
    // the total number of checked boxes
    if ( elems[i].checked ) count++;
    }
    }
    return count;
    }

    There are other ways of doing this, but you asked for an easy one.

    Hope that helps,

    Mike

    --
    Michael Winter
    M.Winter@blueyo nder.co.uk.invalid (remove ".invalid" to reply)

    Comment

    Working...