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

SyntaxError: missing ; before statement 1: at line 2 Acrobat Pro X

New Here ,
Feb 26, 2023 Feb 26, 2023

Hello,

I am new to JS. I am trying to conditionally format two fields. Field one is a dropdown menu called "niche size" with three options: Small, Medium, and Large. Field two is called "Number of Persons." I am trying to code so that:

If Small is selected, Number of Persons = 2

If Medium is selected, Number of Persons = 3

If Large is selected, Number of Persons = 4 

 

I keep getting the error: SyntaxError: missing ; before statement 1: at line 2 even though there is a semicolon after at the end of line 1. I am totally new at this and am probably missing something easy or am doing something glaringly wrong. Help is greatly appreciated. Code below:

 

var Niche Size = this.getField("Number of Persons").valueAsString;

if (Niche Size =="Small") event.value = 2;

else if (Niche Size =="Medium") event.value = 3;

else if (Niche Size =="Large") event.value = 4;

else event.value = "";

TOPICS
Acrobat SDK and JavaScript , Windows
2.8K
Translate
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 , Feb 26, 2023 Feb 26, 2023

Don't use spaces in variable names.

E.g. change Niche Size to Niche_Size.

Translate
Community Expert ,
Feb 26, 2023 Feb 26, 2023

Don't use spaces in variable names.

E.g. change Niche Size to Niche_Size.

Translate
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 ,
Feb 27, 2023 Feb 27, 2023

Excellent! Thank you! One more question:

 

Acrobat accepted the code without errors, but it does not automatically populate the event value field. What do I need to set the action to for this to occur?

 

Thanks, again.

Translate
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 ,
Feb 27, 2023 Feb 27, 2023

Double-check all the values in your code. Remember that JS is case-sensitive, so if the value in the drop-down is "small" and you write "Small" in your code, it won't match.

If you still can't figure it out, share the actual file with us.

Translate
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 ,
Feb 27, 2023 Feb 27, 2023

Thanks so much for your help. It is very much appreciated. I am at a loss. I checked cases. I'm sure whatever I'm doing wrong is something obvious but I just can't figure it out. I have attached the file. Thanks, again.

Translate
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 ,
Feb 28, 2023 Feb 28, 2023
LATEST

Did you apply the code (which still has issues) using the Edit All JavaScripts window? If so, the file has been corrupted. You need to re-create it or go back to an earlier version before you did that, and never do it again!

The correct code to use is this, and it should be placed under the Calculation event of the "NumberofPersons" field:

 

var NicheSize = this.getField("NicheSize").valueAsString;
if (NicheSize == "Small") event.value = 2;
else if (NicheSize == "Medium") event.value = 3;
else if (NicheSize == "Large") event.value = 4;
else event.value = "";
Translate
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