By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,237 Members | 1,534 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,237 IT Pros & Developers. It's quick & easy.

ceri

P: n/a
Hello,
I have to count used checkboxes.How habe I to do this in an easy way.
Thank you
Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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)
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.