Copy link to clipboard
Copied
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 = "";
Don't use spaces in variable names.
E.g. change Niche Size to Niche_Size.
Copy link to clipboard
Copied
Don't use spaces in variable names.
E.g. change Niche Size to Niche_Size.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
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 = "";
Find more inspiration, events, and resources on the new Adobe Community
Explore Now