Skip to main content
Inspiring
May 18, 2021
Answered

Show/Hide based on Dropdown selection with Multiple Choices

  • May 18, 2021
  • 3 replies
  • 1312 views

I have a drop down field with loan transfer types listed. There are 13 different options to choose from. I want to be able to select an option from the list and have an additional field show when that option is selected, but hide when it is not. I need to do this for 4 out of the 13 options - and all text fields are different.

 

The dropdown field name is "Amount Override" with options for: None, Loan Payment - Suggested Method, Loan Payment if it exceeds amount, 25% of Loan Payment, 50% of Loan Payment, Loan Due Amount, Loan Due Amount if it exceeds amount, Loan Cycle Balance, Loan Cycle Balance if it exceeds amount, Loan Cycle Balance less credits, Loan Cycle Balance less credits if it exceeds amount, Available Balance, Available Balance in excess of amount.

 

If  None is selected from the dropdown then I want my field that is named "None" to show up - otherwise, I want that to be hidden.

If Loan Payment - Suggested Method is selected from the dropdown then I want my field that is named "LoanPayment" to show up - otherwise, I want that to be hidden.

If Loan Cycle Balance is selected from the dropdown then I want my field that is named "LoanCycleBal" to show up - otherwise, I want that to be hidden.

If Loan Payment if it exceeds amount is selected from the dropdown then I want my field that is named "LoanPaymentExceeds" to show up - otherwise, I want that to be hidden

 

 

I was using the following javascript, but it is hiding the fields no matter what option is selected.

 

if(event.value =="None") {
this.getField("None").display = display.visible;
} else {
this.getField("None").display = display.hidden;
}

if(event.value =="Loan Payment – Suggested Method") {
this.getField("LoanPayment").display = display.visible;
} else {
this.getField("LoanPayment").display = display.hidden;
}

if(event.value =="Loan Payment if it exceeds amount") {
this.getField("LoanPaymentExceeds").display = display.visible;
} else {
this.getField("LoanPaymentExceeds").display = display.hidden;
}

if(event.value =="Loan Cycle Balance") {
this.getField("LoanCycleBal").display = display.visible;
} else {
this.getField("LoanCycleBal").display = display.hidden;
}

 

 

Can someone please help me with this?

This topic has been closed for replies.
Correct answer defaultrfjue3aoi30b

Nesa - I didn't have that box checked, so I checked that and it still wasn't working with what I had.

 

Thom - I went out and found this from the link that you posted and it is working.

 

var nHide = (event.value=="None")?display.visible:display.hidden;

this.getField("None").display = nHide;

var nHide = (event.value=="Loan Payment - Suggested Method")?display.visible:display.hidden;

this.getField("LoanPayment").display = nHide;

var nHide = (event.value=="Loan Cycle Balance ")?display.visible:display.hidden;

this.getField("Cycle").display = nHide;

var nHide = (event.value=="Loan Payment if it exceeds amount")?display.visible:display.hidden;

this.getField("LoanPaymentExceeds").display = nHide;

var nHide = (event.value=="Loan Due Amount")?display.visible:display.hidden;

this.getField("LoanDueAmt").display = nHide;

3 replies

defaultrfjue3aoi30bAuthorCorrect answer
Inspiring
May 18, 2021

Nesa - I didn't have that box checked, so I checked that and it still wasn't working with what I had.

 

Thom - I went out and found this from the link that you posted and it is working.

 

var nHide = (event.value=="None")?display.visible:display.hidden;

this.getField("None").display = nHide;

var nHide = (event.value=="Loan Payment - Suggested Method")?display.visible:display.hidden;

this.getField("LoanPayment").display = nHide;

var nHide = (event.value=="Loan Cycle Balance ")?display.visible:display.hidden;

this.getField("Cycle").display = nHide;

var nHide = (event.value=="Loan Payment if it exceeds amount")?display.visible:display.hidden;

this.getField("LoanPaymentExceeds").display = nHide;

var nHide = (event.value=="Loan Due Amount")?display.visible:display.hidden;

this.getField("LoanDueAmt").display = nHide;

Nesa Nurani
Community Expert
Community Expert
May 18, 2021

In your script, in this line:

if(event.value =="Loan Payment Suggested Method") {

dash (I marked it red) is not same as  in your dropdown field choice:

Loan Payment - Suggested Method (this is taken from your text so check in your file if it's same.)

other then that your code should work, just make sure in dropdown field properties under 'options' tab check " Commit selected value immediately".

 

Thom Parker
Community Expert
Community Expert
May 18, 2021

Read this, it has sample code and explains all.

https://www.pdfscripting.com/public/Hiding-and-Showing-Form-Fields.cfm?sd=40

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often