jpee jpee - 3 days ago 6
Javascript Question

Adobe LiveCycle ES2 JavaScript if-else, else not working

hi there i have been trying for a few days to get a simple if/else script to work.
the issue i am having is when i check syntax it says "error illegal use if reserved word else"

the script i am using is:

if (aira.delsec.presence = "hidden")
airb.tblair._Row1.addInstance(1)
airb.presence = "visible"
aira.delsec.presence = "visible";
else
airb.tblair._Row1.addInstance(1)


also have tried

if (aira.delsec.presence = "hidden");{
airb.tblair._Row1.addInstance(1)
airb.presence = "visible"
aira.delsec.presence = "visible";
} else
{
aira.delsec.presence = "visible";
}


if i remove the else then the if statement works fine. i am really pulling out my hair and any help would be greatly appreciated

Answer

Your JavaScript syntax is wrong. Try:

if (aira.delsec.presence === "hidden") { // use an opening brace, and...
                                         //   === to check for equality...
                                         //   because = assigns a value
  airb.tblair._Row1.addInstance(1);      // end with a semi-colon
  airb.presence = "visible";             // end with a semi-colon
  airb.delsec.presence = "visible";      // end with a semi-colon
} else {                                 // use closing and opening braces
  airb.tblair._Row1.addInstance(1);      // end with a semi-colon
}                                        // use a closing brace

Be sure to use a linting tool to validate your JavaScript as you learn. You will become familiar with the proper syntax more quickly.

Comments