Cerni wrote on 24 Nov 2003:
Hello,
I have to count used checkboxes.How habe I to do this in an easy
way. Thank you
// 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.******@blueyonder.co.uk.invalid (remove ".invalid" to reply)