Skip to main content
Participant
Jan 30, 2023 12:59 PM UTC
Question

Javascript to make all fields visible

I am completely new with javscrtipt.

I got over 100 fileds in form and wanna show them all with one click. Is there any way of doing with simple scripting other than calling the field one by one ?

 

var r1 = this.getField("aa");
var r2 = this.getField("bb");
var r3 = this.getField("cc");
var r4 = this.getField("dd");

 

var flagBtn = this.getField("Flag");
var showAll = flagBtn.buttonGetCaption();
if(showAll == '0')
{
flagBtn.buttonSetCaption('1');
r1.display = display.visible;
r2.display = display.visible;
r3.display = display.visible;
r4.display = display.visible;
}
else
{
flagBtn.buttonSetCaption('0');
r1.display = display.hidden;
r2.display = display.hidden;
r3.display = display.hidden;
r4.display = display.hidden;
}

This topic is closed to new replies. Start a new post to keep the conversation going.

4 replies

try67
Community Expert
Community Expert
Jan 30, 2023 1:03 PM UTC

You can put the names in an array and then use a loop to access all of them, like this:

 

var fields = ["aa", "bb", "cc", "dd"];
var flagBtn = this.getField("Flag");
var showAll = flagBtn.buttonGetCaption();
if (showAll == '0') {
	flagBtn.buttonSetCaption('1');
	for (var i=0; i<fields.length; i++) {
		var f = this.getField(fields[i]);
		f.display = display.visible;
	}
} else {
	flagBtn.buttonSetCaption('0');
	for (var i=0; i<fields.length; i++) {
		var f = this.getField(fields[i]);
		f.display = display.hidden;
	}
	
}
Translate
Participant
Jan 30, 2023 1:07 PM UTC

grouping work as well?

coz over 100 fields 

Translate
try67
Community Expert
Community Expert
Jan 30, 2023 1:13 PM UTC

What do you mean by "grouping"?

Translate