Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2008-10-07
10
Medium Priority
?
1,016 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Getting information about Fonts being used in a PDF file A colleague of mine recently faced an issue related to the PDF file format. The PDFs were containing mission critical client information, they were successfully mailed but there was a sm…
Update 21-May-2015: I temporarily removed the source code and the code snippets to make major changes to the program. Regards, Joe A recent question here at Experts Exchange piqued my interest, so I decided to provide a thorough solution and publ…
In this first video of the three-part Xpdf series, we introduce and describe Xpdf, a library containing nine command line utilities that perform various functions on PDF files. We show where the library is located and how to download it, discuss its…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…

636 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