Solved

PDF JavaScript and ComboBox fields

Posted on 2009-04-03
6
3,504 Views
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.
0
Comment
Question by:bhlang
  • 4
6 Comments
 

Author Comment

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

Accepted Solution

by:
Karl Heinz Kremer earned 500 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:
UpdateComboBox(event.value);

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";

    }

    else

    {

        // ...

    }

    this.getField("ComboBox2").setItems(box2);

    this.getField("Text1").value = text;

}

Open in new window

0
 

Author Comment

by:bhlang
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.
0
 

Author Comment

by:bhlang
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:
Product.x
ProductSource.x
ItemNumber.x
0
 

Author Closing Comment

by:bhlang
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.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

In a previous article published here at Experts Exchange, Signature Image with Transparent Background (http://www.experts-exchange.com/Web_Development/Document_Imaging/A_12380-Signature-Image-with-Transparent-Background.html), I explained how to cre…
This article discusses how to create an extensible mechanism for linked drop downs.
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…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now