Skip to main content
Known Participant
February 22, 2023
Question

Help with Javascript with if else if statement

  • February 22, 2023
  • 2 replies
  • 10670 views

I've found a few posts that seem like they should work for me but I keep getting a SyntaxError: missing ; before statement 1: at line 2

 

My form has 9 sections. Each section has 6 - 16 sub-sections with dropdown fields. The options to select are: Met, Not Met, and Exceeded. I have given them values of 1, 3, and 6, respectively. 

The sum of each section is being captured in field: Objective 1 Score. (I am using the Calculate > Value is the Sum of the following fields option). This field will be hidden as I'm only using it to capture the Score. This field is calculating properly.

 

I want the Score visible to the user to read as either Met, Not Met, or Exceeded, depending on the value calculated above.

  • ≤ 6 = "Not Met"
  • 7-18 = "Met"
  • >19 = "Exceeded"

Here's my script under Calculate > Custom calculation script

 

var Score 1 = "Objective 1 Score";
if ( event.value < 6){
Score 1 = "Not Met";
} else if (( event.value >= 7) && ( event.value < 18)){
Score 1 = "Met";
} else if (event.value >=19){
Score 1 = "Exceeded";
}

 

Like I said, I get the syntax error. I haven't been able to actually test this yet.

 

 

 

 

This topic has been closed for replies.

2 replies

try67
Community Expert
Community Expert
February 22, 2023

Is this the calculation script for "Score 1"? If so, change these lines:

Score 1 = "Not Met";

To this:

event.value = "Not Met";

Thom Parker
Community Expert
Community Expert
February 22, 2023
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Thom Parker
Community Expert
Community Expert
February 22, 2023

In your code

 

var Score 1 = "Objective 1 Score";

 

there is a space in "Score 1". There can be no spaces in variable names. 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
KAmaral84Author
Known Participant
February 23, 2023

The only value I'm receiving back is Not Met. Thoughts?

KAmaral84Author
Known Participant
February 23, 2023

Here's my new function

 

var Score1 = "Objective 1 Score";

if ( event.value < 6){ event.value = "Not Met";

} else if (( event.value > 7) && ( event.value < 18)){

event.value = "Met"; }

else if (event.value > 19){

event.value = "Exceeded";

}