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

Drop-down menu populating text box?

New Here ,
Sep 13, 2017 Sep 13, 2017

Hi,

I work in a warehouse, and we are constantly making creating Bill of Ladings for our trucks.

We have a PDF template that we use currently with text boxes, and are more or less picking up and dropping off at the same 10-20 locations.

How can I make a pull down menu in the shipper section with a list of the usual suspects, that will generate the shippers address underneath, ditto for the consignee?

I'm understand from my research that this is a task for java script. Can someone walk me through this?  Or maybe direct me to a video tutorial? I would love to understand what I'm doing and not just copying and pasting.

Thank you!

O.

TOPICS
PDF forms
22.3K
Translate
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
1 ACCEPTED SOLUTION
LEGEND ,
Sep 13, 2017 Sep 13, 2017

You could use a custom Keystroke script for the dropdown, something like the following:

// Custom Keystroke script for combo box

(function () {

    if (!event.willCommit) {

        // Set up an array of addresses. \r = carriage return

        var aAddr = [];

        aAddr[0] = "1234 56th St. S.\rSeattle, CA 98104";

        aAddr[1] = "5678 Industrial Blvd.\rDenver, CO 80123";

        // Continue below with other addresses

        // Get the export value of the selected item

        var ex_val = event.changeEx;

        // Get the corresponding address

        var addr = aAddr[ex_val];

        // Populate the multiline text field with the address

        getField("Address").value = addr;

    }

})();

The dropdown should be configure to "Commit selected value immediately". The corresponding multiline text field to display the address is assumed to be named "Address", so change to match whatever you're using. Also, you have to set the export value of the items to numbers, starting with 0 for the first item and incrementing by 1 for each subsequent item. So the export values of the items are the same as the corresponding array index of the address.

View solution in original post

Translate
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
LEGEND ,
Sep 13, 2017 Sep 13, 2017

Is the address a single field (multiline) or several fields (address, city, state, zip, etc.) When you say "ditto for the cosignee", do you mean you will have another dropdown, or will it be based on selected shipper?

Translate
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
New Here ,
Sep 13, 2017 Sep 13, 2017

Thanks George for stepping in.

Yes. Address will be 3 lines. Top line will be a drop down with a name, second line street, 3rd city state zip. No need to break it into fields. Maybe 2 total, one pull down with a name, and that will populate an address directly underneath.

I'd like to do the exact same a second time, for the Consignee. A dropmenu with a name, followed by a field for the address.

I appreciate your help.

O.

Translate
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
LEGEND ,
Sep 13, 2017 Sep 13, 2017

You could use a custom Keystroke script for the dropdown, something like the following:

// Custom Keystroke script for combo box

(function () {

    if (!event.willCommit) {

        // Set up an array of addresses. \r = carriage return

        var aAddr = [];

        aAddr[0] = "1234 56th St. S.\rSeattle, CA 98104";

        aAddr[1] = "5678 Industrial Blvd.\rDenver, CO 80123";

        // Continue below with other addresses

        // Get the export value of the selected item

        var ex_val = event.changeEx;

        // Get the corresponding address

        var addr = aAddr[ex_val];

        // Populate the multiline text field with the address

        getField("Address").value = addr;

    }

})();

The dropdown should be configure to "Commit selected value immediately". The corresponding multiline text field to display the address is assumed to be named "Address", so change to match whatever you're using. Also, you have to set the export value of the items to numbers, starting with 0 for the first item and incrementing by 1 for each subsequent item. So the export values of the items are the same as the corresponding array index of the address.

Translate
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
New Here ,
Sep 14, 2017 Sep 14, 2017

It works!

Thank you my friend, you made my day!

Thank you!

O.

Translate
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
New Here ,
Feb 17, 2020 Feb 17, 2020

hello!

I'm trying something similar though the problem is that the combo box populates the export value and not the item name.

any ideas on how to do this and get the item name instead of export value?

Translate
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 17, 2020 Feb 17, 2020

You can get this with the property currentValueIndices of the field and the method getItemAt.

Look at the example of currentValueIndices.

Translate
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
New Here ,
Feb 17, 2020 Feb 17, 2020

the code I'm using is:

(function () {

 

if (!event.willCommit) {

 

var aPrice = [];

aPrice[0] = "5 ";

aPrice[1] = "10 ";

aPrice[2] = "20 ";

 

var aIndex = [];

aIndex[0] = 0;

aIndex[1] = 1;

aIndex[2] = 2;

 

var ex_val = event.changeEx;

 

var price = aPrice[aIndex[ex_val]];

 

getField("amount").value = price;

}

 

})();

 

How can I intergrade this?

Translate
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 18, 2020 Feb 18, 2020

Where does you use this script?

Translate
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
New Here ,
Feb 18, 2020 Feb 18, 2020

this is keystroke script I use in a combo box of "services" that turns to a text box of amounts.

For example:

aItem[1] = "SINGLE "

aIndex[1] = 1

aPrice[1] = "35 "

 

By selecting the "single" in the combo box, the outcome in the text box is the price assigned (for this selection the outcome is 35€ as seen below)

The problem is that once I move to another field, the combo box changes from "single" to "1"

eg. what I get:

Capture1.JPG

what I want:

Capture.JPG

 

 

Translate
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 18, 2020 Feb 18, 2020

Where does you use array aItem?

Translate
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
New Here ,
Feb 18, 2020 Feb 18, 2020

sorry i was trying to make this general example

here is the full code:

 

// Custom Keystroke script for combo box
(function () {

if (!event.willCommit) {

 

var aAddr = [];
aAddr[0] = "0 ";
aAddr[1] = "35 ";
aAddr[2] = "80 ";
aAddr[3] = "165 ";
aAddr[4] = "250 ";
aAddr[5] = " ";
aAddr[6] = "110 ";

 

var aIndex = [];
aIndex[0] = 0;
aIndex[1] = 1;
aIndex[2] = 2;
aIndex[3] = 3;
aIndex[4] = 4;
aIndex[5] = 5;
aIndex[6] = 6;

 

var ex_val = event.changeEx;

var addr = aAddr[aIndex[ex_val]];

getField("amount1").value = addr;

}

})();

Translate
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 18, 2020 Feb 18, 2020

Again. Where does you use array aItem?

Translate
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
New Here ,
Feb 18, 2020 Feb 18, 2020
I'm sorry I don't understand your question. There is no aItem in the code.
Translate
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 18, 2020 Feb 18, 2020

You have post following:
aItem[1] = "SINGLE "

Translate
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
New Here ,
Feb 18, 2020 Feb 18, 2020
This is only for your info it is not in the codethis is why I sent the full code abovethis is for you to see the item name as an example sorry I should not have posted this.
Translate
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
New Here ,
Feb 18, 2020 Feb 18, 2020
can you give me an example of how to use the property currentValueIndices of the field and the method getItemAt in my code?
Translate
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 18, 2020 Feb 18, 2020

There is a example in the Acrobat Javascript Reference.

Translate
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
New Here ,
Feb 18, 2020 Feb 18, 2020
can you give me a link please?
Translate
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 18, 2020 Feb 18, 2020

Search the web for the Reference.

Translate
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
New Here ,
Feb 18, 2020 Feb 18, 2020
LATEST
I created another printable text box instead.thank you for your time though 🙂
Translate
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