Highlighted

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

Community Beginner ,
Sep 16, 2020

Copy link to clipboard

Copied

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? 

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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

TOPICS
Acrobat SDK and JavaScript

Views

84

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

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

Community Beginner ,
Sep 16, 2020

Copy link to clipboard

Copied

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? 

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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

TOPICS
Acrobat SDK and JavaScript

Views

85

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Sep 16, 2020 0
Most Valuable Participant ,
Sep 16, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 16, 2020 0
Community Beginner ,
Sep 16, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 16, 2020 0
Adobe Community Professional ,
Sep 16, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 16, 2020 0
Community Beginner ,
Sep 16, 2020

Copy link to clipboard

Copied

Thank you, that worked!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 16, 2020 0