Skip to main content
jonathanm75257324
Known Participant
May 24, 2019
Answered

If one checkbox of 15 is checked then show/hide a field

  • May 24, 2019
  • 2 replies
  • 3001 views

I have a group of 15 check boxes, if one of them (or more) is checked, then I would like field to show. If none are checked, the field disappears. How would I do this?

Additionally, if the check boxes and fields are updated (if spawned), how would this work?

This topic has been closed for replies.
Correct answer try67

the debugger says that "event.target.replace" is not a function.


Sorry, first line should be:

var baseName = event.target.name.replace("User1_Reporting_Cover", ""); 

2 replies

jonathanm75257324
Known Participant
May 28, 2019

Can you give me a sample code that I can adjust to?

My code spawns as follows: P3.User_Page1.User1_Wire_Cover

try67
Community Expert
Community Expert
May 28, 2019

Try this:

var baseName = event.target.replace("User1_Reporting_Cover", "");

var bShow = false;

for (var i=1; i<=15; i++) {

    if (this.getField(baseName + "User1_Account"+i+"_Reporting").valueAsString!="Off") {

        bShow = true;

        break;

    }

}

event.target.display = bShow ? display.visible : display.hidden;

jonathanm75257324
Known Participant
May 28, 2019

the debugger says that "event.target.replace" is not a function.

try67
Community Expert
Community Expert
May 24, 2019

The first part is quite simple, but the second part is much more complicated.
Regarding the first: What are the names of those check-boxes, and of the field to show/hide?

jonathanm75257324
Known Participant
May 24, 2019

The names of the check boxes are as follows: "User1_Account1_Reporting", "User1_Account2_Reporting", "User1_Account3_Reporting", "User1_Account4_Reporting", through "User1_Account15_Reporting".

The field is called "User1_Reporting_Cover"

try67
Community Expert
Community Expert
May 24, 2019

OK. You can use this code as the custom calculation script of "User1_Reporting_Cover", then:

var bShow = false;

for (var i=1; i<=15; i++) {

    if (this.getField("User1_Account"+i+"_Reporting").valueAsString!="Off") {

        bShow = true;

        break;

    }

}

event.target.display = bShow ? display.visible : display.hidden;