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
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