Skip to main content
Participant
October 5, 2024
Question

JavaScript Assistance Required - Syntax error missing before statement

  • October 5, 2024
  • 2 replies
  • 439 views

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.

This topic has been closed for replies.

2 replies

try67
Community Expert
Community Expert
October 5, 2024

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;

Bernd Alheit
Community Expert
Community Expert
October 5, 2024

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