• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
14

PDF Dropdown JavaScript Show/Hide Help

Community Beginner ,
Feb 08, 2024 Feb 08, 2024

Copy link to clipboard

Copied

Can anyone take a look at my PDF & script to tell me how to get the hidden addresses to appear when an option from the dropdown is selected.

 

Test file attached. Right now, you have to click on a selection from the dropdown, THEN click again anywhere on the PDF for that selection to appear.

 

Script I'm using:

 

var display = { visible: display.visible, hidden: display.hidden }; 

 

function showAddress() {

     var locationValue = this.getField("Location").value; 

 

this.getField("Address1").display = display.hidden;

this.getField("Address2").display = display.hidden;

this.getField("Address3").display = display.hidden;

 

// Show the corresponding display field based on the selected location

if (locationValue === "City, ST 1") {

     this.getField("Address1").display = display.visible;

} else if (locationValue === "City, ST 2") {

     this.getField("Address2").display = display.visible;

} else if (locationValue === "City, ST 3") {

     this.getField("Address3").display = display.visible;

}

}

 

this.getField("Location").setAction("OnBlur", "showAddress()");

TOPICS
JavaScript , PDF , PDF forms

Views

330

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 08, 2024 Feb 08, 2024

You're script is "over-written", i.e., most of it is unnecessary, and improperly placed. 

Put this in the Validation Script for the dropdown.

this.getField("Address1").display = display.hidden;
this.getField("Address2").display = display.hidden;
this.getField("Address3").display = display.hidden;
 
// Show the corresponding display field based on the selected location
if (event.value == "City, ST 1") {
     this.getField("Address1").display = display.visible;
} else if (event.value == "City, ST 
...

Votes

Translate

Translate
Community Expert ,
Feb 08, 2024 Feb 08, 2024

Copy link to clipboard

Copied

You're script is "over-written", i.e., most of it is unnecessary, and improperly placed. 

Put this in the Validation Script for the dropdown.

this.getField("Address1").display = display.hidden;
this.getField("Address2").display = display.hidden;
this.getField("Address3").display = display.hidden;
 
// Show the corresponding display field based on the selected location
if (event.value == "City, ST 1") {
     this.getField("Address1").display = display.visible;
} else if (event.value == "City, ST 2") {
     this.getField("Address2").display = display.visible;
} else if (event.value == "City, ST 3") {
     this.getField("Address3").display = display.visible;
}

 

That's all you need, plus set the "commit seleted immediately" option for the dropdown field.

 

Read more about this topic here:

https://www.pdfscripting.com/public/Hiding-and-Showing-Form-Fields.cfm

https://www.pdfscripting.com/public/List-Field-Usage-and-Handling.cfm

 

 

 

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 09, 2024 Feb 09, 2024

Copy link to clipboard

Copied

How would I set the "commit selected immediately" in here. Sorry, this is new to me.

 

Thanks for the help so far! 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 09, 2024 Feb 09, 2024

Copy link to clipboard

Copied

You are Welcome!

Here's an article on editing field properties. 

https://www.pdfscripting.com/public/Editing-Fields-Properties.cfm

 

Look on the "Options" tab on the Field Properties Dialog for the dropdown. 

 

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 19, 2024 Feb 19, 2024

Copy link to clipboard

Copied

LATEST

This is exactly what I needed and did it!

 

And for those who still might be having issues and you're starting your file out in INDD first, I had to go into each address in INDD (that I had converted into a button) and uncheck the "Hidden Until Triggered" option. Let the JavaScript do the hiding for you.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines