PDA

View Full Version : Adding numbers in a loop



jntcomputers
Mar 20th, 2007, 10:26 PM
I have a script that I want to add the quantities of products. So far I have this:


var productACount = 0;
var productBCount = 0;
for (i = 0; (i < data.length); i++) {
pcount = i+1;
data[i] = unescape(data[i]);
var nameVal = data[i].split('=');
var utilityType = nameVal[0].split('_');
if(utilityType[0] != "utility") { //Not a utlity
if (nameVal[0] != 'Submit') { // Get rid of Submit button
//Get product type
var productType = nameVal[0].substring(0, 5); // i.e. Washer or Dryer
var productColumn = nameVal[0].substring(6, 5); // i.e. A or B
var productRowCount = nameVal[0].substring(7, 5); // i.e. A1, A2, A3... so on
var productQty = nameVal[0].substring(7, 10);
if (productColumn == 'A') {
if (productQty != 'qty') {
washersArrayA.push(nameVal[1]); }
else { // quantity
var count = nameVal[1]
washersQtyArrayA.push(nameVal[1]);
var productACount = productACount + count;
}
}
}
}


If the quantities are 0, 1 & 10... this output 0110

sage45
Mar 20th, 2007, 10:50 PM
Try using:
var productACount = Number(productACount) + Number(count);HTH,

-sage-