Copy link to clipboard
Copied
Hello,
I have a question about Acrobat Pro 2017 and JavaScript.
I would like to have several values calculated in a form. I have entered the following code for each in the user-defined calculation script.
Field 1:
var a = this.getField ("Working_1_Employee1");
var b = this.getField ("Working_time_2_Employee1");
var c = this.getField ("Working_3_Employee1");
var d = this.getField ("Working_4_Employees1");
var e = this.getField ("Working_5_Employee1");
if (a.value) {event.value = a.value + b.value + c.value + d.value + e.value; } else {
event.value = "";}
Field 2:
var a = this.getField ("Director_1_Employee1");
var b = this.getField ("Director_2_Employee1");
var c = this.getField ("Director_3_Employees1");
var d = this.getField ("Regie_4_Mitarbeiter1");
var e = this.getField ("Regie_5_Emitarbeiter1");
if (a.value)
{event.value = a.value + b.value + c.value + d.value + e.value;
} else {event.value = ""; }
Field 2 should then also be subtracted from field 1 if there are values. For this I entered the following.
Field 3:
var a = this.getField ("Total working hours_Employees1");
var b = this.getField ("Director-Total_Employees1");
if (b.value) {event.value = a.value - b.value; } else {
event.value = "";}
Now I have the following problems.
If, for example, the field Arbeitszeit_3_Emitarbeiter1 is not filled, the value in field 1 is not completely added up but the value from a + b is added together and the values from d and e are written after it.
It is the same in field 2.
If nothing is entered, 0.00 should not appear in the calculation fields, since the forms are also printed out and filled out manually every now and then.
Can someone give me an optimization for this or show where I can find an example in order to understand the function more. I'm still pretty much at the beginning.
Many Thanks.
Copy link to clipboard
Copied
You checks only the value of a. Check also the values of the other fields.
Copy link to clipboard
Copied
Change the first code to:
var a = this.getField("Working_1_Employee1").valueAsString;
var b = this.getField("Working_time_2_Employee1").valueAsString;
var c = this.getField("Working_3_Employee1").valueAsString;
var d = this.getField("Working_4_Employees1").valueAsString;
var e = this.getField("Working_5_Employee1").valueAsString;
if (a && b && c && d && e) {
event.value = Number(a) + Number(b) + Number(c) + Number(d) + Number(e);
} else {
event.value = "";
}
And follow a similar pattern for the other fields.