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

Help wioth very simple form calculations

TrishPRRD
Registered: Feb 17 2010
Posts: 8

I am very new to creating fillable forms and using Javascript and I thought I had figured out how to add 2 fields together to get a total and then determine the percentage of the 2 fields. However, I keep getting crazy percentages when I change the values that I enter. This is important because I can see the form users changing the values a few times before they submit the form to our organization.

Here's what I need to do,

1) in column one: add values 1 and 2 (as entered by user) to get a TOTAL
2) in column two: determine the % of the total for both 1 and 2 (i.e., value 1/TOTAL= % and value 2/TOTAL = %)

To get the TOTAL I used the following script:
var a =this.getField("1");
var b =this.getField("2");
event.value=a.value+b.value;
if(event.value==0)event.value=""

To get the % in column two for the % of 1/TOTAL I used:
var a =this.getField("1");
var b =this.getField("TOTAL");
event.value=(a.value/b.value);
if(TOTAL==0) {event.value="";} else event.value = TOTAL;

To get the % in column two for the % of 2/TOTAL I used:
var a =this.getField("2");
var b =this.getField("TOTAL");
event.value=(a.value/b.value);
if(TOTAL==0) {event.value="";} else event.value = TOTAL;

For instance, when I enter 50 for value 1 and 50 for value 2 I get a total of 100. But the % comes out to 55.56% for each, where it should be 50%.

please help

My Product Information:
Acrobat Standard 9.0, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2399
There's a problem with this line:
if(TOTAL==0) {event.value="";} else event.value = TOTAL;

Read it carefully. This means that your value can only be 0 or "".
You never define any variable called "TOTAL"...
I suggest you re-write the code with more significant names. That way it will be easier to spot the problems.

Also, check your field calculation order.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
This sounds like the field calculation order is not in the proper sequence. You need to edit the field calculation order, "Forms => Edit in Acrobat" "Forms => Edit Fields => Edit field calculation order...", and set the order to first calculate the Total and then peroration fields.You should also check for division by zero.

George Kaiser

TrishPRRD
Registered: Feb 17 2010
Posts: 8
I made some changes based on both your suggestions and now it is working perfectly! thank you :)