Skip to main content
Inspiring
April 15, 2024
Answered

Need to make form field names into an array in javscript.

Hi there,

 

I have 15 form fields that i would like to be made into an array so they can be made visible in one go. 

 

So instead of me having to type out the javascript as the below:

 

{this.getField("Sect-3 EDN TF1").display = display.visible;
this.getField("Sect-3 EDN TF2").display = display.visible;
this.getField("Sect-3 EDN TF3").display = display.visible;
this.getField("Sect-3 EDN TF4").display = display.visible;
this.getField("Sect-3 EDN TF5").display = display.visible;
this.getField("Sect-3 EDN TF6").display = display.visible;
this.getField("Sect-3 EDN TF7").display = display.visible;
this.getField("Sect-3 EDN TF8").display = display.visible;
this.getField("Sect-3 EDN TF9").display = display.visible;
this.getField("Sect-3 EDN TF10").display = display.visible;
this.getField("Sect-3 EDN TF11").display = display.visible;
this.getField("Sect-3 EDN TF12").display = display.visible;
this.getField("Sect-3 EDN TF13").display = display.visible;
this.getField("Sect-3 EDN TF14").display = display.visible;
this.getField("Sect-3 EDN TF15").display = display.visible;}

 

I would like to be able to set a variable next to the textfield names. 

 

Many thanks in advance, 

 

Steve

This topic is closed to new replies. Start a new post to keep the conversation going.
try67
try67Correct answer
Community Expert
April 15, 2024

You don't even need to use an array. This code will work just as well:

 

for (var i=1; i<=15; i++) {
	this.getField("Sect-3 EDN TF"+i).display = display.visible;
}

2 replies

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
April 15, 2024

You don't even need to use an array. This code will work just as well:

 

for (var i=1; i<=15; i++) {
	this.getField("Sect-3 EDN TF"+i).display = display.visible;
}
Translate
Inspiring
April 15, 2024

Perfect, many thanks

Translate