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()");
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
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
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!
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.
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now