Reputation: 101
I'm very new to JS and writing scripts. Right now, I am creating a form in Acrobat and calculating 5 fields, the result of which will be the value of another field. I don't know anything about writing if/else statements, but I feel like thats what I might need for the script to function right, because the totaled value only appears (and works fine) if all of the other values are entered. But all of them won't always be entered (sometimes v1, v2 & v3 won't be entered at all), so I need something that will enable the script/value to work even if one or more of those values aren't present. What I have right now is:
(function () {
var v1 = +getField("Charges1").value;
var v2 = +getField("Charges2").value;
var v3 = +getField("Charges3").value;
var v4 = +getField("NetWeight").value;
var v5 = +getField("MRMRate").value;
event.value = (v4 * v5) * (v1 + v2 + v3);
})();
Any help at all would be appreciated – thank you!
Upvotes: 0
Views: 50
Reputation: 3615
You do not need a function definition for this, if you put the script in the Calculate event of the field containing the result.
This code should work (unless, see below)
var v1 = this.getField("Charges1").value;
var v2 = this.getField("Charges2").value;
var v3 = this.getField("Charges3").value;
var v4 = this.getField("NetWeight").value;
var v5 = this.getField("MRMRate").value;
event.value = (v4 * v5) * (v1*1 + v2*1 + v3*1);
This should display a value, even if it is just 0. It may not display anything if the result field is formatted to display nothing if its value is 0 (check the Format tab in the field properties about that).
Upvotes: 1