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

JavaScript Error in Adobe Acrobat Pro

New Here ,
Jul 16, 2018 Jul 16, 2018

Copy link to clipboard

Copied

I am trying to write a script to auto-calculate a Goal by multiplying the Total Contract Value by the selection from the drop down box.  Here is my stab at it but I am getting a Syntax Error before statement 2 at line 3.  Any help is appreciated.

Thank you!

if(this.getField("Type of Contract").value=='Construction (10% Goal)'){

event.value=nTotal Contract Value*0.10;

}else if(this.getField("Type of Contract").value=='Non-Construction (3% Goal)'){

event.value=nTotal Contract Value*0.03;

}else{

event.value=0//}

TOPICS
Acrobat SDK and JavaScript

Views

391

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

correct answers 1 Correct answer

Community Expert , Jul 16, 2018 Jul 16, 2018

Hi,

As you appear to be using the field multiple times, your code might be easier to use  if it looks like this,

// as we use the value multiple times, just get it once.

var totalFieldValue = this.getField("Type of Contract").value;

var fieldValueToUse = this.getField ("Total Contract Value").value;

if(totalFieldValue =='Construction (10% Goal)')

{

     event.value=fieldValueToUse*0.10;

}

else if( totalFieldValue=='Non-Construction (3% Goal)')

{

     event.value=fieldValueToUse*0.03;

}

else

{

     event.value=

...

Votes

Translate

Translate
Community Expert ,
Jul 16, 2018 Jul 16, 2018

Copy link to clipboard

Copied

What is this:

nTotal Contract 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 ,
Jul 16, 2018 Jul 16, 2018

Copy link to clipboard

Copied

Total Contract Value is the name of the field in my Acrobat Form.  I was guessing when I created this script and used the 'n' in front b/c i saw that in another example.

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 ,
Jul 16, 2018 Jul 16, 2018

Copy link to clipboard

Copied

This is the snip of what I'm working on.  Sorry its so messy - I am less than a novice on this.

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 ,
Jul 16, 2018 Jul 16, 2018

Copy link to clipboard

Copied

Hi,

As you appear to be using the field multiple times, your code might be easier to use  if it looks like this,

// as we use the value multiple times, just get it once.

var totalFieldValue = this.getField("Type of Contract").value;

var fieldValueToUse = this.getField ("Total Contract Value").value;

if(totalFieldValue =='Construction (10% Goal)')

{

     event.value=fieldValueToUse*0.10;

}

else if( totalFieldValue=='Non-Construction (3% Goal)')

{

     event.value=fieldValueToUse*0.03;

}

else

{

     event.value=0;

}

Hope this helps

Malcolm

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 ,
Jul 16, 2018 Jul 16, 2018

Copy link to clipboard

Copied

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
New Here ,
Jul 16, 2018 Jul 16, 2018

Copy link to clipboard

Copied

What if I am trying to sum the contract amounts in the following table based on whether they selected "Yes" in the Section 3 Business Concern column?  I want the sum to be in the first section in the Est. Section 3 Business Concern Utilization field.

Thank you!

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 ,
Jul 16, 2018 Jul 16, 2018

Copy link to clipboard

Copied

HI,

So if the user clicks, Yes in the Section 3 Business concern box, we populate the Est. Contract Amount with the value of the sum, if they click NO, what is supposed to happen?

Regards

Malcolm

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 ,
Jul 16, 2018 Jul 16, 2018

Copy link to clipboard

Copied

If they click "no", we don't want the contract amount to be added to the Est. Section 3 Business Concern Utilization field.  We only want the contract amounts that are checked "yes" to be added up.  🙂

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 ,
Jul 16, 2018 Jul 16, 2018

Copy link to clipboard

Copied

Hi,

It is a little tough without seeing the whole form, If can share it using dropbox or similar flle sharing site, I can make the code more specific to your form, but you are wanting to wrap your calculation in a IF statement, probably on the validate function of the  03_Business_Concerns fields, ( we could put it as a Document JavaScript function, and call it from each one, this would make maintenance easier,) I will write it for one box, and you can let us know if  you need more help to enable it for all fields.

(i am assuming the Yes/No is a drop down box)

if ( event.value === Yes)

{

     // put your calculation code here

}

else

{

     this.getField("Amount1").value = ""; // or 0 if that makes more sense for your form

}

Hope this helps

Malcolm

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 ,
Jul 16, 2018 Jul 16, 2018

Copy link to clipboard

Copied

LATEST

Hi Malcom -

here is a shot of the page of the form:

I want to make a formula in #1 that will add the value of the contract entered into #2 only if the box is selected as "yes" in #3.  I'm not sure if that is possible.  It's ok if it is not easy to program.  It's just a bonus if we can automate field #1

Here are the field names:

i really appreciate your help!  😉

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