travisbrown
Technical User
- Dec 31, 2001
- 1,016
I'm trying to loop through a series of checkboxes, but can't get the loop to fire if there is only one checkbox in the collection. Works fine if there is more than one, but the length when there is only one returns undefined. I'm sure it's something obvious, but I don't get it.
See anything?
See anything?
Code:
var cbCollection = document.forms[0].elements['payment'];
var checkboxarray;
var payout = 0;
var invoices = "";
var counter = 0;
for ( var i = 0; i <= cbCollection.length; i++ ) {
if ( cbCollection[i].checked ) {
payout = payout + (document.getElementById('amount_' + i).value*1);
if ( counter == 0 )
{invoices = cbCollection[i].value;}
else
invoices = invoices + ',' + cbCollection[i].value
counter = counter + 1;
}
}