Skip to main content
Participating Frequently
July 16, 2018
Answered

JavaScript Error in Adobe Acrobat Pro

  • July 16, 2018
  • 3 replies
  • 817 views

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

This topic has been closed for replies.
Correct answer BarlaeDC

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

3 replies

BarlaeDC
Community Expert
Community Expert
July 16, 2018

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

mlsverAuthor
Participating Frequently
July 16, 2018

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.  :-)

BarlaeDC
Community Expert
Community Expert
July 16, 2018

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

BarlaeDC
Community Expert
BarlaeDCCommunity ExpertCorrect answer
Community Expert
July 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=0;

}

Hope this helps

Malcolm

mlsverAuthor
Participating Frequently
July 16, 2018

Thank you so much!!!!

Bernd Alheit
Community Expert
Community Expert
July 16, 2018

What is this:

nTotal Contract Value

mlsverAuthor
Participating Frequently
July 16, 2018

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.

mlsverAuthor
Participating Frequently
July 16, 2018

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