Hi, I’m trying to get a field to pull information from either one data field or another, the data fields will never have info at the same time. Will adobe let one field pull info from multiple sources or am I pursuing a fruitless avenue? First I tried several versions of the following, and the event.value field acts like the second to last line concerning v5 doesn’t exist:
var v1 = this.getField("1Kto50KTotal").value;
var v2 = this.getField("50Kto100Ktotal").value;
var v3 = this.getField("100Kto500Ktotal").value;
var v4 = this.getField("500001andUpTotal").value;
var v5 = this.getField("FinRevFeeX15%").value;
var sum = v1 + v2 + v3 + v4
if (sum < 2000) {event.value = sum;}
else if (v5 < 2000) {event.value = v5;}
else {event.value = 2000}
Then I read some more about Boolean expressions and thought I’d found the answer with the Or operator ||, but when I tried the following, I get a message that there is a syntax error in the last line, but I don’t see an error:
var v1 = this.getField("1Kto50KTotal").value;
var v2 = this.getField("50Kto100Ktotal").value;
var v3 = this.getField("100Kto500Ktotal").value;
var v4 = this.getField("500001andUpTotal").value;
var v5 = this.getField("FinRevFeeX15%").value;
var sum = v1 + v2 + v3 + v4
if (sum < 2000) {event.value = sum;}
else {event.value = 2000;}
|| if (v5 < 2000) {event.value = v5;}
else {event.value = 2000;}
Could someone point me in the right direction?
Do you have any other errors?
Have you checked Acrobat's JavaScript console for any messags?
You need to explicitly convert the field values to numbers, like this:
var v1 = +this.getField("1Kto50KTotal").value;
var v2 = +this.getField("50Kto100Ktotal").value;
var v3 = +this.getField("100Kto500Ktotal").value;
var v4 = +this.getField("500001andUpTotal").value;
var v5 = +this.getField("FinRevFeeX15%").value;
That way when you add the values of those variables, you get numerical addition instead of string concatenatiion if any of those fields are blank, and the rest of your script will behave as expected.
You can use boolean expressions inside if, like this:
if ( cond1 || cond2) {
...
}