• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Is it possible to loop through an array to check if certain buttons are visible?

Community Beginner ,
Sep 16, 2020 Sep 16, 2020

Copy link to clipboard

Copied

Sorry, I know this may be a weird question:

 

I know how to loop through sequentially to hide all buttons. This is what I've used:

for (var i = 1; i < 54; i++) {
getField("Button" + i).display = display.hidden;
}

 and that works fine for me.

 

Where I'm stuck is I'd like to use an if statement to cycle through a random list of the buttons to check if they are visible or not visible. I know you can declare array variables, but I have no idea how to implement all of this.

 

I know I could type it all in, but I'd like to reuse this with maybe different button numbers at some point, so i'd just like to change the array.

 

Say for sake of argument I'd like the if statement to check if Button2, Button3, Button5,Button9, Button18 and Button 46 are visible and that all the other buttons up to 53 are hidden.

 

Is this possible without doing the following and having to type it for every button:

if(this.getField("Button1").display=display.hidden && this.getField("Button2").display=display.visible &&
this.getField("Button3").display=display.visible &&
this.getField("Button4").display=display.hidden //ETC ETC

 

I hope that makes sense? Any help gratefully received!

TOPICS
Acrobat SDK and JavaScript

Views

194

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
community guidelines
Community Expert ,
Sep 16, 2020 Sep 16, 2020

Copy link to clipboard

Copied

About arrays in Javascript&colon;

https://www.w3schools.com/js/js_arrays.asp 

Votes

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
community guidelines
Community Expert ,
Sep 16, 2020 Sep 16, 2020

Copy link to clipboard

Copied

LATEST

Hi,

 

Depending on how many fields you have (that are not buttons) you might be able to use. This gets all the fields in a document and then checks if they are buttons, once you know it is a button you could code to allow for above

 

for ( var i = 0; i < doc.numFields; i++){
var curField = doc.getField(doc.getNthFieldName(i));
if ( curField.type == "button"){
// do some logic to work out if it is hidden or not
}
}

 Regards

 

Malcolm

Votes

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
community guidelines