Copy link to clipboard
Copied
In the Completion field i have entered a simple formula to get the percentage to display. The formula is (CumulativeAmount1/Budget1)*100 by the way. the math works correctly but the problem i'm having now is that when the first 3 fields in the row are left empty it just blows up and gives me the "Value entered does not match the format of [Field]" error. i'm looking for a fix for that. i'd also like for the fields to remain empty unless a value is entered into any of the first 3 fields in the row.
i have zero skills at this. all i know are the basics of Excel formulas so please forgive my ignorance.
any help would be appreciated.
Copy link to clipboard
Copied
OK, so, let's first dig up some math skills: What happens when you divide a value by zero? Yep, the result is + or - Infinity (not beyond here…). What happens when you divide zero by zero? Yep, the result is undefined.
With that, we have the cause of the problem; division by zero. What to do when we program such a formula?
That means working a bit on Acrobat Forms and JavaScript skills…
Let's assume that your table is set up so that the name of each field in a row ends with the row number. Let's also assume that you have 8 rows in the table. Finally, let's assume that the Percentage field is formatted as Percentage.
It is considered Best Practice to consolidate all scripts into one single script, and to add it to the Calculate event of a hidden, readonly field, which is otherwise not involved in any way with the rest of the form.
The segment of the script which does the percentage calculation may then look like this:
for (var i = 1 ; i <= 8 ; i++) {
if (this.getField("CumulativeAmount" + i).value != this.getField("CumulativeAmount" + i).defaultValue && this.getField("Budget" +i).value != this.getField("Budget" + i).defaultValue) {
this.getField("Percentage" + i).value = this.getField("CumulativeAmount" + i).value*1 / this.getField("Budget" + i).value*1 ;
}
}
And that should do it (note that the script has 5 lines in total; one or two lines may break).
Hope this can help.
Copy link to clipboard
Copied
Thanks for responding.
i was with you up until you started talking scripts. i understand what they are for and i was able to follow it for the first line but after that it's just way beyond what i can understand. i have only taken one C++ class and that was nearly 15 years ago and i was horrible at it. i dont even know where to being with what you gave me.
i dont need the completion column to display a percentage, just a number to 2 decimals. which i have it doing. is there a way to make the field only be seen and active when values have been inserted into the fields in it's formula? or get it to display a "-" like excel does?