Domino Code Fragment

Code Name*
Calculating array values in JavaScript
Date*
07/08/2000
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.
Description*
This JavaScript function uses a global variable listSize which is computed from the formula @Elements(someList). The list is really an array of <INPUT> fields called total and quantity. Note that if the array has only one element you cannot use the array construct, you must reference the field directly.
Type*
JavaScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code:

Because the fields are created with the HTML <INPUT> tag, a Notes field called total and one called quantity will be necessary on the form or the Domino server will not allow you to submit it. Also note that the calculated values are stored in three fields on the form: subtotal, totalsList, and qList.

function calcSubtotalColumn ( ) {
var subtotal = 0;
var subtotalList = "";
var qtyList = "";


if (listSize == 1) {
subtotal = makeIntoNumber(document.forms[0].total.value);
subtotalList = document.forms[0].total.value;
qtyList = document.forms[0].qty.value;
}
else {
for (i = 0; i < listSize; i++) {
subtotal = subtotal + makeIntoNumber(document.forms[0].total[i].value);
subtotalList = subtotalList + ";" + document.forms[0].total[i].value;
qtyList = qtyList + ";" + document.forms[0].qty[i].value;
}
}
document.forms[0].subtotal.value = formatAsCurrencyString( subtotal );
document.forms[0].totalsList.value = subtotalList;
document.forms[0].qList.value = qtyList;
return;
}