Skip to main content
Participant
February 27, 2023
Answered

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

  • February 27, 2023
  • 1 reply
  • 3223 views

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

This topic has been closed for replies.
Correct answer Bernd Alheit

Don't use spaces in variable names.

E.g. change Niche Size to Niche_Size.

1 reply

Bernd Alheit
Community Expert
Bernd AlheitCommunity ExpertCorrect answer
Community Expert
February 27, 2023

Don't use spaces in variable names.

E.g. change Niche Size to Niche_Size.

Participant
February 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.

try67
Community Expert
Community Expert
February 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.