These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Select document to open from selection made in a Combo Box

cdworker
Registered: Jul 27 2006
Posts: 2

I am a javascript novice and need help in programming a simple selection from a Combo Box. The Combo Box will have a list of products - Product1, Product2, ...
I want a different PDF to open depending on the selection. E.g. ProductOne.pdf; ProductTwo.pdf ...

Any help with the javascript for this (ora better way to do it) will be appreciated.

Tia.

Jeff

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
If you have used Acrobat to make your form, use the switch statement to evaluate the selection and set a string variable with the name of the file to open. The JavaScript will go in the "On Blur" action for the combo box.

// select document file name
var sFileName; // variable for file name

switch (this.getField(event.target.name).value) {

case "Select Document":
sFileName = ""; // empty file name
break;

case "Product 1":
sFileName = "ProductOne.PDF";
break;

case "Product 2":
sFileName = "ProductTwo.PDF";
break;

case "Product 3":
sFileName = "ProductThree.PDF";
break;

default:
sFileName = ""; //empty file name
app.alert("Unknown Selection: " + event.value);
break;
} // end selection

// open non-empty file name
if (sFileName != "") {
// open using relative path name
var otherDoc = app.openDoc(sFileName, this); // open selected doc
this.closeDoc(); // close current document
}

The above is not possible in Live Cycle Designer because Live Cycle Designer does not include the "app.openDod()" method.

George Kaiser

Mollies Mom
Registered: Feb 10 2010
Posts: 8
This topic looks like the perfect solution to my situation. However, I am getting no response when I test the form. ComboBox is called "Chapters". I'm trying to easily move between chapters selected from a list.
Any ideas what I'm missing? Using Acrobat Pro 9.

Script:
// select document file name
var sFileName; // variable for file name

switch (this.getField(event.target.name).value) {

case "(Chapters)":
sFileName = ""; // empty file name
break;

case "Chapter 3":
sFileName = "Chapter3.pdf";
break;

case "Chapter 6":
sFileName = "Chapter6.pdf";
break;

default:
sFileName = ""; //empty file name
app.alert("Unknown Selection: " + event.value);
break;
} // end selection

// open non-empty file name
if (sFileName != "") {
// open using relative path name
var otherDoc = app.openDoc(sFileName, this); // open selected doc
this.closeDoc(); // close current document
}
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Are there any errors in the console when you run the script?

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

maxwyss
Registered: Jul 25 2006
Posts: 255
In which event (and which field) have you attached the code?

Also, is the "disclosed" document property set for the chapters files?

HTH.