Skip to main content
Participant
Dec 6, 2022 2:53 PM UTC
Question

If/Else Javascript statements for a PDF form

I have created a form that needs an IF Else JavaScript. The form has a field that we enter either a Y (for yes) or N (for no). Another field, Field B,  looks at whether there is a Y or N in FieldA and needs to either perform a calculation (product  of FieldC * FieldD) if FieldA is a Y and return the result , or return a value of 0 if FieldA is an N. Did I mention I have zero JavaScript skills? So far I have this, but I keep getting "SyntaxError: missing ) in parenthetical 3: at line 4:

var nSubTotal = this.getField("PP").valueAsString;
if(nSubTotal === 'Y') {
event.value = ( OF INSTALLMENTS * Numb of Txble Parcels );
}
else if (nSubTotal === 'N') {
event.value = 0;
}

This topic is closed to new replies. Start a new post to keep the conversation going.

4 replies

Nesa Nurani
Community Expert
Community Expert
Dec 6, 2022 3:40 PM UTC

You can use this as custom calculation script of "Field B", just change field names to your actual filed names:

var a = this.getField("Field A").valueAsString;
var c = Number(this.getField("Field C").valueAsString);
var d = Number(this.getField("Field D").valueAsString);

if(a == "Y")
event.value = c*d;
else if(a == "N")
event.value = 0;
else
event.value = "";

Translate
Participant
Dec 6, 2022 3:53 PM UTC

Thank you so much! 

Translate
try67
Community Expert
Community Expert
Dec 6, 2022 2:54 PM UTC

You can't just write out the field names in order to access their values. You need to use the proper methods and properties for that, like this:

this.getField("Field Name").value

Translate
Participant
Dec 6, 2022 3:38 PM UTC

Thank you very much for the reply.

Translate