This has been driving me crazy today. I need to be able to loop thru 4 fields and display the total in the total field. it works great when I first open up the form but when I start to manually enter data, the fields do not recalculate properly. if I click total1 and enter a value then the value that was PREVIOUSLY there in total2 completely disappears.
There are a total of 5 fields (TOTAL[0] ---> TOTAL[4]) that I want to total into a field named "HINCTOTAL".
Heres my code from the TOTAL[0]-
var IncomeTypeDesc = this.getField("HINC011[0]");
var Wagetype = this.getField("HINC012[0]");
var EarnedIncAmount = this.getField("HINC013[0]");
var hoursworked = this.getField("HINC014[0]");
var UnEarnedIncAmount = this.getField("HINC015[0]");
var lasttwelve = this.getField("HINC017[0]");
var incomeamountdisp = this.getField("TOTAL[0]");
//then I do calc based on what comes from the DB:
if (IncomeTypeDesc.value != "Job" && IncomeTypeDesc.value != "")
{
incomeamountdisp.value = UnEarnedIncAmount.value
}
else
if (Wagetype.value == "HOURLY")
{
incomeamountdisp.value = EarnedIncAmount.value * hoursworked.value * 4.33
}
else
if (Wagetype.value == "WEEKLY")
{
incomeamountdisp.value = EarnedIncAmount.value * 4.33
}
else
if (Wagetype.value == "BI-WEEKLY")
{
incomeamountdisp.value = EarnedIncAmount.value * 2.16
}
else
if (Wagetype.value == "MONTHLY")
{
incomeamountdisp.value = EarnedIncAmount.value
}
else
if (Wagetype.value == "ANNUAL")
{
incomeamountdisp.value = EarnedIncAmount.value
}
else
{
incomeamountdisp.value = EarnedIncAmount.value
}
//next I format the fields into dollar amounts
//format dollars and cents
var aFieldName = incomeamountdisp.value;
// specify the numeric field options
var nDec = 2; // number of decimal places
var sepStyle = 0; // 1,234.56
negStyle = 0 ; // black minus
currStyle = ''; // reserved
strCurrency = '$'; // USD sign
bCurrencyPrepend = true; // place before number
var fn = this.getField(aFieldName);
fn.setAction({cTrigger: 'Format', cScript: 'AFNumber_Format(nDec, sepStyle, negStyle, currStyle, strCurrency, bCurrencyPrepend)'});
//I tried adding the following line of code in hopes that it would force a //recalculation. it did not work.
this.setPageAction(0, "Open", "this.calculateNow();");
Here is my code from the HINCTOTAL field:
var totalCnt = 0;
var totalField = this.getField("HINCTOTAL")
totalField.value = totalCnt; // initialize the field
for (i=0; i<5; i++)
{
totalField.value += this.getField("TOTAL["+ i +"]").value;
}
it works great when i first bring up the form but I need to be able to reenter values and then have them total out again in the HINCTOTAL field. Can some one help me out with this? oh ,this form was done in acrobat 8.1.
Also, the calculation script for the HINCTOTAL field should look like:
var totalCnt = 0;
for (i=0; i<5; i++) {
totalCnt += +getField("TOTAL["+ i +"]").value;
}
// Set this field value to the sum
event.value = totalCnt;