Skip to main content
Participant
December 6, 2022
Question

If/Else Javascript statements for a PDF form

  • December 6, 2022
  • 2 replies
  • 643 views

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 has been closed for replies.

2 replies

Nesa Nurani
Community Expert
Community Expert
December 6, 2022

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 = "";

Participant
December 6, 2022

Thank you so much! 

try67
Community Expert
Community Expert
December 6, 2022

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

Participant
December 6, 2022

Thank you very much for the reply.