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.
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;
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;
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?
Copy link to clipboard
Copied
Same concept:
var total = 0;
for (var i=1; i<=10; i++) total+=Number(this.getField("Field"+i).valueAsString);