简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM