Thanks gkaiseril,
I read George's post before initially responding and i couldn't figure out how to get util.printf() to work. In The linked post, it looks like it was using a custom calculation script. In my form I am using simplified field notation's like:
simple: GroceriesB-GroceriesS
complex: Income-ThithesB-CharityB-EFundB-MortgageB-HomeItemsB-HomeRepairsB-ElecticB-GasB-WaterB-SewerB-TrashB-PhoneB-InternetB-AutoInsB-UmbrellaB-IdentityB-CosmeticsB-ToiletriesB-PocketEBB-PocketCBB-GiftsB-HouseSuppliesB-PersonalOtherB-PersonalOther2B-GroceriesB-RestaurantsB-ClothingB-CarGasB-CarRepairsB-CarOtherB-MedicalBillsB-MedicalOtherB-EntertainmentB-VacationB-DebtCarB-DebtStudentLoan1B-DebtStudentLoan2B-DebtStudentLoan3B-DebtCreditB-DebtOther1B-DebtOther2B
is there anyway to adapt util.printf() to work with my simplified field notation or do i need to redo my entire form using custom calculation script?
The custom calculation script can be something like the following:
// Get the Income field value, as a number
var v1 = +getField("Income").value;
// Set up an array of field names
var aFieldsToSubtract = [
"ThithesB",
"CharityB",
"EFundB",
"MortgageB",
"HomeItemsB",
"HomeRepairsB",
"ElecticB",
"GasB",
"WaterB",
"SewerB",
"TrashB",
"PhoneB",
"InternetB",
"AutoInsB",
"UmbrellaB",
"IdentityB",
"CosmeticsB",
"ToiletriesB",
"PocketEBB",
"PocketCBB",
"GiftsB",
"HouseSuppliesB",
"PersonalOtherB",
"PersonalOther2B",
"GroceriesB",
"RestaurantsB",
"ClothingB",
"CarGasB",
"CarRepairsB",
"CarOtherB",
"MedicalBillsB",
"MedicalOtherB",
"EntertainmentB",
"VacationB",
"DebtCarB",
"DebtStudentLoan1B",
"DebtStudentLoan2B",
"DebtStudentLoan3B",
"DebtCreditB",
"DebtOther1B",
"DebtOther2B"
];
// Subtract the field values
for (var i = 0; i < aFieldsToSubtract.length, i += 1) {
v1 -= +getField(aFieldsToSubtract).value;
}
// Set this field value by rounding the result to the nearest hundredth
event.value = util.printf("%.2f", v1);
Don't think of this as a band-aid, think of it as the correct way to perform the calculation, because it is. Note that "Thithes" may be a misspelling.