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

For loop when reading inputs from checkboxs

New Here ,
Aug 02, 2018 Aug 02, 2018

Greetings All,

So the premise is I'm trying to create a print button which checks which buttons are checked off, then prints off the ones which are checked off.

I've got the following code so far:

//The following code outputs which page numbers to print based off of checkbox into Field "Print_pages"

//all checkboxes are named "print1", "print2", print3", etc.

//initial page which will always print

var output = "[0,0]";

event.value = output;

//conditional pages, the output for each checkbox is in ",[1,3]" format

if(this.getField("print1").isBoxChecked(0) == "1"){

event.value += this.getField("print1").value;

}

if(this.getField("print2").isBoxChecked(0) == "1"){

event.value += this.getField("print2").value;

}

if(this.getField("print3").isBoxChecked(0) == "1"){

event.value += this.getField("print3").value;

}

//  etc. etc.

//

//

// Print button

var pp = this.getPrintParams();

pp.printRange=[this.getField("Print_pages").value];

this.print(pp);

Question) Is there anyway to condense the if statement into a for loop in above code until there are no more print checkbox fields?

TOPICS
Acrobat SDK and JavaScript , Windows
552
Translate
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

correct answers 1 Correct answer

Community Expert , Aug 02, 2018 Aug 02, 2018

You can use something like this:

var i=1;

var f = this.getField("print1");

while (f!=null) {

    if (f.isBoxChecked(0)){

        event.value += f.value;

    }

    i++;

    f = this.getField("print"+i)

}

Translate
Community Expert ,
Aug 02, 2018 Aug 02, 2018

You can use something like this:

var i=1;

var f = this.getField("print1");

while (f!=null) {

    if (f.isBoxChecked(0)){

        event.value += f.value;

    }

    i++;

    f = this.getField("print"+i)

}

Translate
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
New Here ,
Aug 04, 2018 Aug 04, 2018
LATEST

Works perfectly! Thank you!

Translate
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