Search code examples
javascriptadobelivecycle-designer

Adobe LiveCycle ES2 JavaScript if-else, else not working


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, I 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.


Solution

  • 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.