Skip to main content
Participant
February 25, 2020
Question

Display/Hide multiple fields based on dropdown selection

  • February 25, 2020
  • 1 reply
  • 1936 views

I'm using Acrobat Pro DC and I'm somewhere between Novice and Amateur user level with JS. 🙂

 

I'm creating a form with a dropdown list that I would like to trigger whether or not specific other fields are displayed or hidden to the user based on the choice. I've found similar situations in other cases, but nothing that quite fits what I'm trying.

 

I have used the following successfully, but I'm trying to find a faster way to reference the common fields that will be hidden or displayed based on the selection....especially as I'm looking at adding more as the form develops. I'm running this as a custom validation script on the dropdown.

 

This worked:
if (event.value == "Reclassify a Filled Position") {
this.getField("EmplName").display = display.visible;
this.getField("EmployeeName").display = display.visible;
this.getField("EmplID").display = display.visible;
this.getField("EmplIDNum").display = display.visible;
this.getField("EndDate").display = display.hidden;
this.getField("EndDt").display = display.hidden;
}
else if (event.value == "Special Pay Increase - Temporary") {
selectedSPI.display = display.visible;
this.getField("EmplName").display = display.visible;
this.getField("EmployeeName").display = display.visible;
this.getField("EmplID").display = display.visible;
this.getField("EmplIDNum").display = display.visible;
this.getField("EndDate").display = display.visible;
this.getField("EndDt").display = display.visible;
}

 

This didn't work the way I wanted:

var selectSPI = this.getField("SPIType");
var selectFilled = this.getField("EmplName" && "EmployeeName" && "EmplID"&&"EmplIDNum");
var selectVacant = this.getField("ReqHireRng" && "HireRng");
var selectTemp = this.getField("EndDate" && "EndDt");

 

if (event.value == "Reclassify a Filled Position") {
selectFilled.display = display.visible;
selectSPI.display = display.hidden;
selectVacant.display = display.hidden;
selectTemp.display = display.hidden;
}
else if (event.value == "Special Pay Increase - Permanent") {
selectFilled.display = display.visible;
selectSPI.display = display.visible;
selectVacant.display = display.hidden;
selectTemp.display = display.hidden;

(etc)

 

So really, I guess I'm trying to find out if here's a way to reference numerous fields in a variable and how to do it. I found something related to using switch cases, but I'm not sure how I'd implement it in this scenario.

 

Thanks!

This topic has been closed for replies.

1 reply

Bernd Alheit
Community Expert
Community Expert
February 25, 2020

You can put field names in an array and use a loop over the array.