Skip to main content
Inspiring
February 24, 2020
Answered

Making a field hidden or visible based on check box series

  • February 24, 2020
  • 1 reply
  • 2604 views

Hi,

 

How can I make a text field visible based on a check box selection ? I tried the following: 

if (this.getField("MyCheckBox").isBoxChecked(0))
{this.getField("TextFormFieldToBeDisplayed").display = display.visible;}
else
{this.getField("TextFormFieldToBeDisplayed").display = display.hidden;}

But my check box is apart of a series .. I have 2 check boxes all called "template"

and their export values are individual, and multiple.

 

I am trying to make 1 text box visible and another one hidden if individual is selected, then reversed if multiple is selected.

 

Thank you!

This topic has been closed for replies.
Correct answer try67

If neither is selected then I would like the text box realted in "individual" to be visible and "multiple" hidden.

I pasted this code into the custom calculate of the text boxes. 


Use a separate (hidden) text field with the following code as the custom calculation script:

 

var v = this.getField("MyCheckBox").valueAsString;
if (v=="Off" || v=="individual") {
	this.getField("Field1").display = display.visible;
	this.getField("Field2").display = display.hidden;
} else {
	this.getField("Field1").display = display.hidden;
	this.getField("Field2").display = display.visible;
}

 

Change the field names as needed, of course.

1 reply

try67
Community Expert
Community Expert
February 24, 2020

What about if neither one is selected? Also, where did you place this code?

Inspiring
February 25, 2020

One always has to be selected for the siuation. Either one or the other is hidden. The question on the form is mandatory. 

try67
Community Expert
Community Expert
February 25, 2020

That doesn't mean it will always be the case. The user will be able to un-select both fields, and the script has to take that into consideration or you will get strange and probably unwanted results.