Skip to main content
Participant
Nov 3, 2022 5:15 PM UTC
Question

data change in a PDF based off a dropdown selection

Hello, I am trying to combine three different forms we have at work into one. The only difference is some addresses and phone number information. It differs between each of our locations. I want to combine them into one, where a customer can select the location in a drop down, and text fields will appear based on their selection, which would be the correct shipping and contact information on the form. 

 

I have went through a couple different threads and tried different codes but can't seem to either make it work correctly, or I am doing the wrong thing. Thank you for any help.

This topic is closed to new replies. Start a new post to keep the conversation going.

5 replies

Thom Parker
Community Expert
Community Expert
Nov 8, 2022 7:08 PM UTC

Do you mean that you want the "Ship To" address to change based on the dropdown selection?

 

If so, then this question has been answered many times, in fact weekly at least, on this forum. 

 

Here's some simple code that can be used in a validation script on the dropdown, it shows how you can accomplish this task, it doens't use the information from your form, you'll need to change the field names and data to fit your form.

 

 

if(event.value == "Location1")
   this.getField("ShipTo").value = "First Address";
else if(event.value == "Location2")
   this.getField("ShipTo").value = "Second Address";
else if(event.value == "Location3")
   this.getField("ShipTo").value = "Third Address";
else 
   this.getField("ShipTo").value = "";

 

 

This code uses a rather simple and direct solution. There are many other ways this could be done depending on the requirements of the specific form. 

Here are some articles that provide more detailed info.

https://acrobatusers.com/tutorials/change_another_field/

https://acrobatusers.com/tutorials/js_list_combo_livecycle/

https://acrobatusers.com/tutorials/list_and_combo_in_lc/

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

 

 

Translate
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participant
Nov 8, 2022 8:27 PM UTC

I need all data on the right side in part 2 to change. So it would need to be more than one field.

Translate
Thom Parker
Community Expert
Community Expert
Nov 8, 2022 8:43 PM UTC

In that case, this simple solution is to expand the solution I already provided to include the new fields. 

 

if(event.value == "Location1"){
   this.getField("PartII_4A").value = "Something1";
   this.getField("ShipTo").value = "First Address";
}else if(event.value == "Location2"){
   this.getField("PartII_4A").value = "Something2";
   this.getField("ShipTo").value = "Second Address";
}else if(event.value == "Location3"){
   this.getField("PartII_4A").value = "Something3";
   this.getField("ShipTo").value = "Third Address";
}else{ 
   this.getField("PartII_4A").value = "";
   this.getField("ShipTo").value = "";
}

 

You can see how this technique gets more unwieldy as more fields are added.  But its straight forward and simple.
There are more sophisticted solutions that organize the data better, which are outlined in the articles I've linked in the previous post.   

 

 

Translate
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
BarlaeDC
Community Expert
Community Expert
Nov 8, 2022 12:54 PM UTC

Hi,

 

CAn you post the form ( or a sample form ) that has the drop down and the address fields that you are trying to use so that we can see the problem and offer a solution.

Translate
Participant
Nov 8, 2022 2:03 PM UTC

Attached are the three forms I am trying to combine. If you look in the upper right, the name of the location is there. I was thinking about turning this into a drop down box and having each location listed. And when you select each location it pre fills all the address fields.

Translate