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

JavaScript Assistance Required - Syntax error missing before statement

New Here ,
Oct 04, 2024 Oct 04, 2024

I am getting this syntax error, "SyntaxError: missing ; before statement 1: at line 2."

Here is the code I have:

var P&ADate = this.getField("P&ADate").valueAsString;

if (P&ADate=="") event.value = "";
else (
var date = util.scand("mm/dd/yyyy", P&ADate);

 

var addTime = this.getField("AddTime").value;

 

var days = 0;
if (addTime != "Off") (
     switch (addTime) (
     case "45days" :
            days = 44;
            break;

     )
    date.setDate(date.getDate()+days);
    event.value = util.printd("mm/dd/yyyy", date);
)
else (
      event.value = "";
)
)

 

The goal is when the checkbox is selected, a date of 45 days will be calculated and populated. The 45 days is based on an initial request date appearing in a calendar field. 

For example, my initial request is 10/4/2024. I check the P&ADate box. A date of 11/18/2024 is displayed.

 

Any assistance is greatly appreciated.

TOPICS
PDF , PDF forms
300
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 ,
Oct 04, 2024 Oct 04, 2024

Don't use & in the name of the variable.

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 ,
Oct 05, 2024 Oct 05, 2024
LATEST

Also, this part is unnecessarily convoluted:

if (addTime != "Off") (
     switch (addTime) (
     case "45days" :
            days = 44;
            break;

     )

 

You can replace it with this:

 

if (addTime=="45days") days = 44;

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