Solved

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

Posted on 2008-10-07
10
836 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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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
 

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Update 21-May-2015: I temporarily removed the source code and the code snippets to make major changes to the program. Regards, Joe INTRODUCTION This Article is a follow-up to the Article entitled How To Rename-Move a Batch of PDF Files Based o…
PDF files have been in the limelight due to its unmatched features.  Personal documents, emails, business reports and eBooks are all converted into PDF files owing to peerless features provided by it. Adding watermark to a PDF file is a method to se…
Sometimes we receive PDF files that are in the wrong orientation. They may be sideways or even upside down. This most commonly happens with scanned or faxed documents. It is possible to rotate the view of these PDFs with the free Adobe Reader produc…
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…

770 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