Skip to main content
Participating Frequently
Sep 16, 2020 8:05 AM UTC
Answered

Javascript IF statement works, but the ELSE statement doesn't work.

I've got this Javascript attached to a button

function FindOCG(cName) { 
    var aOCGs = this.getOCGs(); 
    for(var i=0; aOCGs && i<aOCGs.length;i++) { 
        if(aOCGs[i].name == cName) return aOCGs[i]; 
    } 
    return null; 
}
if (FindOCG("Layer 1").state==!true && 
FindOCG("Layer 2").state==!true &&
FindOCG("Layer 3").state==!true &&
FindOCG("Layer 4").state==!true &&
FindOCG("Layer 5").state==!true &&
FindOCG("Layer 6").state==!true &&
FindOCG("Layer 7").state==!true &&
FindOCG("Layer 8").state==!true &&
FindOCG("Layer 9").state==!true &&
FindOCG("Layer 10").state==!true &&
FindOCG("Layer 11").state==true &&
FindOCG("Layer 12").state==!true &&
FindOCG("Layer 13").state==!true &&
FindOCG("Layer 14").state==true &&
FindOCG("Layer 15").state==!true &&
FindOCG("Layer 16").state==!true &&
FindOCG("Layer 17").state==!true &&
FindOCG("Layer 18").state==!true &&
FindOCG("Layer 19").state==!true &&
FindOCG("Layer 20").state==true &&
FindOCG("Layer 21").state==!true &&
FindOCG("Layer 22").state==!true &&
FindOCG("Layer 23").state==true &&
FindOCG("Layer 24").state==!true &&
FindOCG("Layer 25").state==true &&
FindOCG("Layer 26").state==!true &&
FindOCG("Layer 27").state==!true &&
FindOCG("Layer 28").state==!true &&
FindOCG("Layer 29").state==!true &&
FindOCG("Layer 30").state==!true &&
FindOCG("Layer 31").state==!true &&
FindOCG("Layer 32").state==!true &&
FindOCG("Layer 33").state==!true &&
FindOCG("Layer 34").state==!true &&
FindOCG("Layer 35").state==!true &&
FindOCG("Layer 36").state==!true &&
FindOCG("Layer 37").state==!true &&
FindOCG("Layer 38").state==!true &&
FindOCG("Layer 39").state==!true &&
FindOCG("Layer 40").state==true &&
FindOCG("Layer 41").state==!true &&
FindOCG("Layer 42").state==true &&
FindOCG("Layer 43").state==true &&
FindOCG("Layer 44").state==true &&
FindOCG("Layer 45").state==!true &&
FindOCG("Layer 46").state==!true &&
FindOCG("Layer 47").state==!true &&
FindOCG("Layer 48").state==!true &&
FindOCG("Layer 49").state==!true &&
FindOCG("Layer 50").state==true &&
FindOCG("Layer 51").state==!true &&
FindOCG("Layer 52").state==true &&
FindOCG("Layer 53").state==true)
{
this.getField("Complete").display=display.visible;
}
Else
{
this.getField("Wrong").display=display.visible;
}

 

The "complete" button shows up fine when the correct layers are visible (and it doesn't show up if the wrong ones are visible) BUT I wanted the button "Wrong" to appear if the layers visible are not the ones I want. I don't know why this isn't work. Has anyone got any insights please? 

This topic is closed to new replies. Start a new post to keep the conversation going.
try67
try67Correct answer
Community Expert
Sep 16, 2020 8:11 AM UTC

That's probably because it's "else", not "Else"... JS is case-sensitive, remember.

4 replies

BarlaeDC
Community Expert
Community Expert
Sep 16, 2020 8:12 AM UTC

HI,

 

I would change the Else to else ( all small letters).

 

If that doesn't work, can you share the document ? and then check the obvious, make sure field names match.

 

Regards

 

Malcolm

Translate
Participating Frequently
Sep 16, 2020 8:14 AM UTC

Thank you, that worked!

Translate
try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
Sep 16, 2020 8:11 AM UTC

That's probably because it's "else", not "Else"... JS is case-sensitive, remember.

Translate
Participating Frequently
Sep 16, 2020 8:12 AM UTC

Thank you! I'm so used to VBA that I forget it's case sensitive!

Translate