Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


PDF JavaScript and ComboBox fields

Posted on 2009-04-03
Medium Priority
Last Modified: 2012-05-06
I'm building a new PDF invoice form.
I want to be able to have the user select an item from a Product combo-box and have it fill in two additional fields (one of which is a combo-box and the other is a text field) based on what is selected in the first field. I have to use Adobe Acrobat JavaScript to handle this.

What's the best approach?

Here's what I'm thinking so far (haven't laid out anything yet, this is still in the design phase):
1. Create a JavaScript array in a button to populate the Product field with both an item and an export value for that item. This lets me maintain one list to populate all Product fields from.
2. Create a JavaScript function that triggers on change on the Product field. This would have to set the value of the second drop down (Product Source combo-box) as well as the Item Number (text field). It could draw either the item or export value from the Product combo-box. The Product Source (second combo-box) needs to be a combo-box as there will be multiple sources for each product. The part number will stay the same regardless, hence the need for a text-box instead of a combo-box.

What I'm looking for (for you to receive the points) is a working example:
Drop-down list that triggers an update of the contents of a second drop-down list and a textbox.

Note to standard JavaScript developers who aren't familiar with Adobe Acrobat JavaScript - there are differences. Not all code that will work in a web browser will work in a PDF file. Please test your code before sending me on a wild goose chase :) I don't really like chasing wild geese.
Question by:bhlang
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4

Author Comment

ID: 24064024
Note: I will be AFK for the weekend and will be checking on Monday for responses.
LVL 44

Accepted Solution

Karl Heinz Kremer earned 1000 total points
ID: 24067038
It sounds like you are already familiar enough with Acrobat's JavaScript to tackle this (you know about the difference between item value and export value for example).

Here is how I would structure it: All the JavaScript functions that get called by your UI elements would be on the document level. This way, you can then keep the actual handler code for the onSelect or onClick events relatively small.

There is one trick you need to know: Usually with a list box or a combo box, your action script is executed only when the field loses focus. You don't want that, because the user would have to tab out of the control in order to have the second combo box populated: On the properties dialog, select the Options tab and make sure that "Commit selected value immediately" is selected.

Create a custom validation script. Just keep it simple and enter the following into the edit field:

Now you need to create that function. Select Advanced>Document Processing>Document JavaScripts...
Create a new script named UpdateComboBox - use the following code:

function UpdateComboBox(val)
    var box2 = new Array();
    var text = "";
    if (val == "Item1")
        box2 = ["One", "Two", "Three"];
        text = "Text1";
    else if (val == "Item2")
       box2 = ["AAAA", "BBBB", "CCCC"];
        text = "Text2";
    else if (val == "Item3")
       box2 = ["I", "II", "III", "IV", "V"];
        text = "Text3";
    else if (val = "Item 4")
       box2 = ["Four", "Three", "Two", "One"];
        text = "Text 4";
        // ...
    this.getField("Text1").value = text;

Open in new window


Author Comment

ID: 24079186
OK. Your answer looks pretty good.
Some additional info:
The second drop-down is pre-populated with Product Sources. Can I select an item from that list with Javascript? Basically I want the user to select a product from the first list. This will select the standard Product Source and fill in the Product Number. Then if the user wants to select a different Product Source, they can.

Author Comment

ID: 24079557
Also, how can I extend this to a multi-line invoice? The example posted works fine for one line. I need to extend to multiple lines.
I'm using hierarchical field names:

Author Closing Comment

ID: 32957737
Question was partially answered, and then no followup came for my follow up questions. The solution as provided did what I needed, but was incomplete.

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
In this third video of the Xpdf series, we discuss and demonstrate the PDFtoText utility, which converts PDF files into plain text files. Download and install the software.: You may have already downloaded and installed the Xpdf tools while watching…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question