• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

If/Else Javascript statements for a PDF form

New Here ,
Dec 06, 2022 Dec 06, 2022

Copy link to clipboard

Copied

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;
}

TOPICS
Acrobat SDK and JavaScript

Views

476

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 06, 2022 Dec 06, 2022

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 06, 2022 Dec 06, 2022

Copy link to clipboard

Copied

Thank you very much for the reply.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 06, 2022 Dec 06, 2022

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 06, 2022 Dec 06, 2022

Copy link to clipboard

Copied

LATEST

Thank you so much! 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines