Solved

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

Posted on 2008-10-07
10
802 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
Comment Utility
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
Comment Utility
Thank you for the prompt response. Will give it a try and get back to you.
0
 

Author Comment

by:dartanion_jm
Comment Utility
"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
Comment Utility
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
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:dartanion_jm
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks :)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
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…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
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…

762 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

7 Experts available now in Live!

Get 1:1 Help Now