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

How to change fields with similar names in an easier way?

Guest
Jun 23, 2020 Jun 23, 2020

Copy link to clipboard

Copied

Hello.


I have 10 fields with very similar names, the beginning of the name is identical, what changes is only the end, which goes from number 1 to 10.

 

I want to create two buttons:
1) By clicking on this button, the display of fields 1 to 5 is visible. And the display of fields 6 to 10 is hidden.
2) The opposite happens. Display of fields 1 to 5 is hidden. And the display of fields 6 to 10 is visible.

 

Is there an easy way to do this?
I was doing it this way:
this.getField("Field1").display = display.visible;
this.getField("Field2").display = display.visible;
And etc., one line for each field.

 

But this seems to be a very inefficient way.

 

Thank you.

TOPICS
Acrobat SDK and JavaScript

Views

534

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

correct answers 1 Correct answer

Community Expert , Jun 23, 2020 Jun 23, 2020

You can use a loop, like this:

for (var i=1; i<=5; i++) this.getField("Field"+i).display = display.visible;

for (var i=6; i<=10; i++) this.getField("Field"+i).display = display.hidden;

Votes

Translate

Translate
Community Expert ,
Jun 23, 2020 Jun 23, 2020

Copy link to clipboard

Copied

You can use a loop, like this:

for (var i=1; i<=5; i++) this.getField("Field"+i).display = display.visible;

for (var i=6; i<=10; i++) this.getField("Field"+i).display = display.hidden;

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
Guest
Jun 23, 2020 Jun 23, 2020

Copy link to clipboard

Copied

Thank you! It is exactly what I needed.

Another thing ... and if I need to sum these same 10 fields and insert the value in a variable, how should I do it?

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 ,
Jun 23, 2020 Jun 23, 2020

Copy link to clipboard

Copied

LATEST

Same concept:

 

var total = 0;

for (var i=1; i<=10; i++) total+=Number(this.getField("Field"+i).valueAsString);

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