Skip to main content
Known Participant
June 14, 2025
Answered

Show Text Field if Checkbox checked and another Text Field contains text

  • June 14, 2025
  • 3 replies
  • 1059 views

If have Checkbox1, Text Field1, Text Field2, Text Field3, Text Field4 and Text Field5.  I would like to show and hide as follows:

 

CB1 not checked and TF1 contains no text = show TF2, hide TF3, TF4 and TF5

CB1 not checked and TF1 contains text = show TF3, hide TF2, TF4 and TF5

CB1 checked and TF1 contains text = show TF4, hide TF2, TF3 and TF5

CB1 checked and TF1 contains no text = show TF5, hide TF2, TF3 and TF4

Correct answer JR Boulay

In the script provided by JR Boulay it's missing 'C' in each condition

Oops!

It's always better with a test file.

Attached.

 

var CB1 = this.getField("Checkbox1");
var Tx1 = this.getField("Text Field1");
var B1 = this.getField("Button1");
var B2 = this.getField("Button2");
var B3 = this.getField("Button3");
var B4 = this.getField("Button4");

B1.display = display.hidden;
B2.display = display.hidden;
B3.display = display.hidden;
B4.display = display.hidden;

if (CB1.value === "Off" && Tx1.value === Tx1.defaultValue) {B1.display = display.noPrint;}
else if (CB1.value === "Off" && Tx1.value != Tx1.defaultValue) {B2.display = display.noPrint;}
else if (CB1.value != "Off" && Tx1.value != Tx1.defaultValue) {	B3.display = display.noPrint;}
else if (CB1.value != "Off" && Tx1.value === Tx1.defaultValue) {B4.display = display.noPrint;}

3 replies

JR Boulay
Community Expert
JR BoulayCommunity ExpertCorrect answer
Community Expert
June 18, 2025

In the script provided by JR Boulay it's missing 'C' in each condition

Oops!

It's always better with a test file.

Attached.

 

var CB1 = this.getField("Checkbox1");
var Tx1 = this.getField("Text Field1");
var B1 = this.getField("Button1");
var B2 = this.getField("Button2");
var B3 = this.getField("Button3");
var B4 = this.getField("Button4");

B1.display = display.hidden;
B2.display = display.hidden;
B3.display = display.hidden;
B4.display = display.hidden;

if (CB1.value === "Off" && Tx1.value === Tx1.defaultValue) {B1.display = display.noPrint;}
else if (CB1.value === "Off" && Tx1.value != Tx1.defaultValue) {B2.display = display.noPrint;}
else if (CB1.value != "Off" && Tx1.value != Tx1.defaultValue) {	B3.display = display.noPrint;}
else if (CB1.value != "Off" && Tx1.value === Tx1.defaultValue) {B4.display = display.noPrint;}
Acrobate du PDF, InDesigner et Photoshopographe
Known Participant
June 18, 2025

That worked.  Thank you!

JR Boulay
Community Expert
Community Expert
June 15, 2025

Add an invisible text field and place this script as calculation script:

 

var CB1 = this.getField("Checkbox1");
var Tx1 = this.getField("TextField1");
var B1 = this.getField("Button1");
var B2 = this.getField("Button2");
var B3 = this.getField("Button3");
var B4 = this.getField("Button4");

B1.display = display.hidden;
B2.display = display.hidden;
B3.display = display.hidden;
B4.display = display.hidden;

if (B1.value === "Off" && Tx1.value === Tx1.defaultValue) {B1.display = display.noPrint;}
else if (B1.value === "Off" && Tx1.value != Tx1.defaultValue) {B2.display = display.noPrint;}
else if (B1.value != "Off" && Tx1.value != Tx1.defaultValue) {	B3.display = display.noPrint;}
else if (B1.value != "Off" && Tx1.value === Tx1.defaultValue) {B4.display = display.noPrint;}
Acrobate du PDF, InDesigner et Photoshopographe
Known Participant
June 17, 2025

Entering text in Text Field1 makes Button3 visible, removing text makes Button4 visible.  Checking Checkbox1 has no effect.

Nesa Nurani
Community Expert
Community Expert
June 17, 2025

In the script provided by JR Boulay it's missing 'C' in each condition, it should look like this if(CB1.value

Known Participant
June 14, 2025

When I said show, what I meant to say was visible but doesn't print.

Known Participant
June 15, 2025

One more update.  I have buttons, not text fields.  The correct question is:

 

If have Checkbox1, Text Field1, Button1, Button2, Button3 and Button4.  I would like to noPrint and hide as follows:

 

CB1 not checked and TF1 contains no text = noPrint B1, hide B2, B3 and B4

CB1 not checked and TF1 contains text = noPrint B2, hide B1, B3 and B4

CB1 checked and TF1 contains text = noPrint B3, hide B1, B2 and B4

CB1 checked and TF1 contains no text = noPrint B4, hide B1, B2 and B3