Solved

How do I populate a text box with a list box?

Posted on 2008-10-07
10
822 Views
Last Modified: 2011-10-19
Acroforms - Javascript - Adobe Acrobat Pro v8.12

Hello all...

How can I use Acrobat javascript to populate a text box with
the multi selected values from a list box?

EXAMPLE:

---------------------
   MultiSelect
    Listbox1

<Blank>
Apples
[Oranges]  <--Selected
Pears
Cherries
[Grapes]   <--Selected
Figs
[Plums]    <--Selected
---------------------

RESULTS:
---------------------
    Textbox1

Selected: Oranges, Grapes, Plums
---------------------

I placed the following Keyboard Script in
Combo box2, to populate Textbox2 with the
selection from Combo box2:

var targ1=getField("Textbox2");
if(!event.willCommit){
    targ1.value=event.change;
}

Can it be modified to handle the multi selected
items in listbox1 to populate Textbox1?
0
Comment
Question by:dartanion_jm
  • 5
  • 5
10 Comments
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 22668202
Do you have the "JavaScript for Acrobat API Reference" document from Adobe? You need that if you want to do any serious JavaScript development.

Take a look at the property "currentValueIndices" of the Field  class. The following code is based on the example given in the reference document.

I've not actually run this in an Acrobat environment, so it may not work the way I've written it, but it's at least very close. Once you have access tot the reference manual, and look up the currentValueIndices property, you should be able to get things working. If not, let me know, and I'll actually create a PDF file that shows how this can work.



var textFieldNewValue = ""
 

var f = this.getField("ListBox1");

var a = f.currentValueIndices;
 

if (typeof a == "number") // A single selection

{

     textFieldNewValue = f.getItemAt(a, false));

}

else // Multiple selections

{

    console.println("Selection:");

    for (var i = 0; i < a.length; i ++)

    {

        if (i!=0_

        {

            textFieldNewValue += " ";

        }

         textFieldNewValue += f.getItemAt(a[i], false);

    }

}
 

targ1.value = textFieldNewValue;

Open in new window

0
 

Author Comment

by:dartanion_jm
ID: 22675820
Thank you for the prompt response. Will give it a try and get back to you.
0
 

Author Comment

by:dartanion_jm
ID: 22687980
"If not, let me know, and I'll actually create a PDF file that shows how this can work."

I'm going to take you up on your gracious offer to create a PDF file.

When trying the script, I got the following error message:

  Error:  Missing ; before: statement 6 at line 7

                    textFieldNewValue = f.getItemAt(a, false));
  Error---->  }
                   else // Multiple selections
                   {

Couldn't figure it out. (Reference:  Adobe Acrobat SDK v8.0 NOV 2006 - Pg 80 / Example 6.2)

Thanks again for your efforts.

0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 22693720
As indicated, I did not actually run this code, so no interpreter had a chance to point out all my typos...

There should only be one closing parenthesis after false:

    textFieldNewValue = f.getItemAt(a, false);
}
else // Multiple selections
{
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 22693744
There was of course one more typo in the code. I now actually run it in a PDF file and came up with the following - corrected -s ample code.

The sample assumes that you have two objects, one list box and one text box. The list box is called ListBox1, and the text field has a custom calculation script that is set to the following program.
var textFieldNewValue = ""

 

var f = this.getField("ListBox1");

var a = f.currentValueIndices;

 

if (typeof a == "number") // A single selection

{

     textFieldNewValue = f.getItemAt(a, false);

}

else // Multiple selections

{

    console.println("Selection:");

    for (var i = 0; i < a.length; i ++)

    {

        if (i!=0)

        {

            textFieldNewValue += " ";

        }

         textFieldNewValue += f.getItemAt(a[i], false);

    }

}

 

event.target.value = textFieldNewValue;

Open in new window

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:dartanion_jm
ID: 22696795
Greetings!

Thank you for your continued efforts.  

I get the following error when trying the last version of the script:

  InvalidSetError: Set not possible, invalid or unknown.
  Field.value:23:Field listbox1:Keystroke

FYI - In my test file the listbox is called "listbox1". I did rename it in the script before running it.

See attached: Listbox_DEV_101208_0517a.pdf

Thanks again.
Listbox-DEV-101208-0517a.pdf
0
 
LVL 44

Accepted Solution

by:
Karl Heinz Kremer earned 500 total points
ID: 22697289
The script has to be associated with the text field. I've modified the PDF file and attached it to this comment. You will see the update in the text field as soon as you commit the values in the list box (e.g. by tabbing out of the list box, or by clicking on any other object on the page).
Listbox-DEV-101208-0517a-modifie.pdf
0
 

Author Closing Comment

by:dartanion_jm
ID: 31504024
The Matrix (1999) - Memorable quote by Morpheus: "You are the One, Neo".  Much Appreciated!   Just what I was looking for. Khkremer.....you are "the One"! Thanks again.
0
 

Author Comment

by:dartanion_jm
ID: 22698084
The Matrix (1999) - Memorable quote by Morpheus: "You are the One, Neo".  Much Appreciated!   Just what I was looking for. Khkremer.....you are "the One"!  Thanks again.
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 22699122
Thanks :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

PaperPort is a popular document imaging/management product from Nuance Communications (http://www.nuance.com/). It is in widespread use by both individuals (http://www.nuance.com/for-individuals/by-product/paperport/index.htm) and businesses (http:/…
This article focuses on how to remove password security from multiple PDF files by Adobe Acrobat program. Sometimes it is essential to access the stored data items and to print, edit as well as copy content from Portable Document Format files in abs…
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 …

947 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

20 Experts available now in Live!

Get 1:1 Help Now