
1. Re: value to be blank unless calc = zero?
George_Johnson May 24, 2011 7:51 PM (in response to psky3)Sure there is. Just get the field values of A and B as strings and see if either both are blank, and only set the field value if they are not. The barebones script would look something like:
(function () { // Get the field values, as strings var v1 = getField("A").valueAsString; var v2 = getField("B").valueAsString; if (v1 && v2) { event.value = +v1 + +v2; } else { event.value = ""; } })();
This could be simplified to just:
(function () { var v1 = getField("A").valueAsString; var v2 = getfield("B").valueAsString; event.value = v1 && v2 ? +v1 + +v2 : ""; })();
Replace "A" and "B" in the code with the actual names of the input fields.
The +v1 and +v2 converts the strings to numbers so you get numerical addition instead of string concatentation
Edit: corrected typo

2. Re: value to be blank unless calc = zero?
psky3 May 24, 2011 8:54 PM (in response to George_Johnson)thanks for the superfast answer! I spent several hours struggling through this on my own, and was nowhere close to this answer, so this is a huge help, and your code is now in four different places on my PDF using subtraction, multiplication and division variations. Thanks again!

3. Re: value to be blank unless calc = zero?
George_Johnson May 24, 2011 9:37 PM (in response to psky3)1 person found this helpfulGreat. Note that when doing division you should add an additional check to make sure the denominator does not evaluate to zero. For example, if the user simply entered a decimal point, the field would not be blank so the code above would accept the value, but when it got converted to a number for the division, it will result in division by zero, which will result in either Infinity, Infinity, or NaN (Not a Number, for 0/0).