Skip to main content
Inspiring
May 8, 2024
Answered

Show or hide text field based on other text fields

  • May 8, 2024
  • 1 reply
  • 678 views

I know how to show or hide a text field if text is entered in another text field, but this is a different twist.  This is what I am looking to do:

 

I have six text fields:  1, 2, A, B, C and D.  Field 1 and 2 are text enterable.  If no text is entered in either field 1 or field 2, I want field A to show and fields B, C and D to be hidden.  If text is entered in field 1 but not field 2, I want field B to show and fields A, C and D to be hidden.  If text is entered in field 2 but not field 1, I want field C to show and fields A, B and D to be hidden.  If text is entered in fields 1 and 2, I want field D to show and fields A, B and C to be hidden.

 

Any help would be appreciated.

This topic has been closed for replies.
Correct answer Nesa Nurani

Put this in one of the text fields as custom calculation script:

 

var f1 = this.getField("1").valueAsString;
var f2 = this.getField("2").valueAsString;
var a = this.getField("A");
var b = this.getField("B");
var c = this.getField("C");
var d = this.getField("D");

a.display = b.display = c.display = d.display = display.hidden;

if (f1 == "" && f2 == "")
 a.display = display.visible;
else if (f1 != "" && f2 == "")
 b.display = display.visible;
else if (f1 == "" && f2 != "")
 c.display = display.visible;
else if (f1 != "" && f2 != "")
 d.display = display.visible;

 

1 reply

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
May 8, 2024

Put this in one of the text fields as custom calculation script:

 

var f1 = this.getField("1").valueAsString;
var f2 = this.getField("2").valueAsString;
var a = this.getField("A");
var b = this.getField("B");
var c = this.getField("C");
var d = this.getField("D");

a.display = b.display = c.display = d.display = display.hidden;

if (f1 == "" && f2 == "")
 a.display = display.visible;
else if (f1 != "" && f2 == "")
 b.display = display.visible;
else if (f1 == "" && f2 != "")
 c.display = display.visible;
else if (f1 != "" && f2 != "")
 d.display = display.visible;

 

BrianG934Author
Inspiring
May 8, 2024

Works perfectly.  Thanks!