Copy link to clipboard
Copied
I have never programmed in Java and need a Java script to insert into a calculation field in an Adobe PDF form I am creating using Adobe Acrobat Pro DC. This form will be one that can be filled out on the PC or printed out and filled in manually. The calculated field will display an unwanted zero when printed out and I want it to be blank. Another field will be a calculated percent and displays an error when there is no divisor; similar problem, I want it to be blank and have the person filing out the form manually to calculate the field and write it in. I don't have time to learn
The Excel formula would be: If(Cell_1A="","",Cell_1A+Cell_1B)
What would the JAVA script be in a "Simplified Field Notation" or "Custom Calculation Script" dialog box?
Both of these things require a custom calculation. For the division script you can use something like this:
var a = Number(this.getField("Field A").value);
var b = Number(this.getField("Field B").value);
if (b==0) event.value = "";
else event.value = a/b;
For the conditional script you can use this:
var a = this.getField("Cell_1A").valueAsString;
var b = this.getField("Cell_1B").valueAsString;
if (a=="") event.value = "";
else event.value = Number(a)+Number(b);
Copy link to clipboard
Copied
Both of these things require a custom calculation. For the division script you can use something like this:
var a = Number(this.getField("Field A").value);
var b = Number(this.getField("Field B").value);
if (b==0) event.value = "";
else event.value = a/b;
For the conditional script you can use this:
var a = this.getField("Cell_1A").valueAsString;
var b = this.getField("Cell_1B").valueAsString;
if (a=="") event.value = "";
else event.value = Number(a)+Number(b);
Copy link to clipboard
Copied
Thank you for the solution. It solved my problem.
Copy link to clipboard
Copied
You should note that this is JavaScript (one word, no space, capital S). It is not Java or Java Script. These would be different things. This may not seem important, but if you are searching the web for advice it's very important not to get the wrong stuff, which will be similar enough to trick you, but won't work.
Copy link to clipboard
Copied
I do appreciate the people who correct my misstatements. In the future I'll use JavaScript correctly. Thank you.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now