Skip to main content
Participant
April 17, 2018
Answered

Acrobat Custom calculation script error

  • April 17, 2018
  • 2 replies
  • 610 views

This is my script.

event.value = 0;

var ProductMargin = this.getField(“ProductMargin”).value;

if (ProductMargin = 0) event.value = 0;

else event.value = this.getField( "MarginPlan").value - this.getField("NetMargin").value;

And I am getting a SyntaxError: illegal character 2: at line 3. Can you tell me what is wrong? Thanks

This topic has been closed for replies.
Correct answer gkaiseril

Many users add some console print statements to verify intermediate values and action results to see the results of their code.

When I use cut and paste to copy your code, I see the appearance of the smart quotation marks that are used in word processors rather then the dumb quotation marks. You can try using the single quotation marks instead of the double quotation marks.  Since JavaScript is a text based programming language you should always use a text edition like notepad, Notepad++, text pad, etc. Avoid Word and Wordpad.

Since this is a freely accessible public forum, you may not want to disclose your too much of you personal information. You might want to add more simple email signature block to your email program leaving out your business links and details.

2 replies

try67
Community Expert
Community Expert
April 18, 2018

You must only use straight, single or double, quotes. Do not use something like Word to edit the code as it tends to automatically convert regular quotes to "fancy" ones, which will invalidate your code. Use a plain-text editor, like Notepad, or Notepad++.

Joel Geraci
Community Expert
Community Expert
April 17, 2018

Can you tell me what is wrong?

Yes - But then you wouldn't learn anything. You are very close though. Take a look at this article JavaScript Comparison and Logical Operators and see if you can see what's wrong with your code.

Participant
April 17, 2018

I added two equal signs like this but still get the same error.

if (ProductMargin == 0) event.value = 0;

I must be doing something else wrong?

[Private info removed -Mod.]

gkaiserilCorrect answer
Inspiring
April 17, 2018

Many users add some console print statements to verify intermediate values and action results to see the results of their code.

When I use cut and paste to copy your code, I see the appearance of the smart quotation marks that are used in word processors rather then the dumb quotation marks. You can try using the single quotation marks instead of the double quotation marks.  Since JavaScript is a text based programming language you should always use a text edition like notepad, Notepad++, text pad, etc. Avoid Word and Wordpad.

Since this is a freely accessible public forum, you may not want to disclose your too much of you personal information. You might want to add more simple email signature block to your email program leaving out your business links and details.