These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Totaling form fields - values disappear when you enter the field

dasmits
Registered: Jan 29 2010
Posts: 19

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.

My Product Information:
Acrobat Pro 8.1, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
You should not be using things like setAction and setPageAction like you are. They are fine for setting up the form in the first place, but once the fields are set up, you don't have to keep doing that.

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;
dasmits
Registered: Jan 29 2010
Posts: 19
thanks for the quick response George. I used your version of code for the HINCTOTAL field but Im still having this problem where I cannot get all of the field values to recalculate. like I get a good total when I first open up the form but when I try to manually enter values it gets hairy. I do have a page open action this.calculateNow();

could that be causing the issue?

Thanks,
Earle
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
That shouldn't matter. It's really hard to tell what's going on without being able to inspect the form. It could be a coding problem or a problem with the field calculation order.
dasmits
Registered: Jan 29 2010
Posts: 19
Hi George. is there a way I could get you to review the form for me?