4 Replies Latest reply on Feb 12, 2013 3:32 AM by Belle7777

    Add item to ListBox in PDF

    Belle7777 Level 1

      Hi,

       

      I have a listbox named INFORMATION in a PDF that I need to populate with data from elsewhere and display the same.

       

      I know how to set the values for a text field

      oDoc.getField("TextFieldName").value = "ABC";

       

      How do I do an addItem for a ListBox field where I need to keep adding items to the ListBox field?

       

      Help appreciated.

       

      Thanks.

        • 1. Re: Add item to ListBox in PDF
          gkaiseril MVP & Adobe Community Professional

          You cannot add items to a list box directly.

           

          You can use the insertItemAt or setItems methods to modify a list box or combo box.

           

          This can only be done with Acrobat unless you provide a PDF with Extended Reader Rights.

           

          Here is a working example of using the instertItemAt, you may need to change the field name:

           

          var oLB = this.getField("List Box1");

          var nItems = oLB.numItems ;

          oLB.insertItemAt("ann", "a", 0); /* inserts sam at top of list */

          oLB.insertItemAt("sam", "s", oLB.numItems); /* inserts sam at end of list */

           

          And for the setTiems:

           

          var oLB = this.getField("List Box1");

          var aItems = new Array(["ann", "a"], "b", "c", ["sam", "s"]);

          oLB.setItems(aItems);

          • 2. Re: Add item to ListBox in PDF
            try67 MVP & Adobe Community Professional

            You can't add a single item to a list, but you can set the entire list of

            items, using the setItems() method.

            You can also use the numItems property and getItemAt method to get a list

            of the current items, then add the new items to it.

            • 3. Re: Add item to ListBox in PDF
              Belle7777 Level 1

              Thank you all!  I was able to use the setItems() method to set all the values to the list box at once.

               

              Could anyone please share with me a link to the comprehensive list of acrobat related javascript information with respect to field types?

              • 4. Re: Add item to ListBox in PDF
                Belle7777 Level 1

                A related question:

                 

                The ListBox shows the first item highlighted as the selected Item.  Since my PDF is going to be for display only (non editable), I need to deselect the default selected Item.

                Can someone tell me how I can do that in Javascript?

                 

                Thanks.