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
  • 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

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
Suggested Courses

607 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