8 Replies Latest reply on May 18, 2014 1:01 PM by Markh1234

    Javascript for dropdown boxes

    Markh1234

      I'm new to Acrobat Pro XI,

       

      I've created a form and I would like to transfer the information selected from a dropdown box , once selected, into a text box using Java script. If possible can you have 2 selections from a dropdown entered into the same text box?

      I've tried various different Java scripts but they don't work. What would the correct Java be? Where should I enter it using Acrobat pro XI?

       

      Many Thanks

       

      Mark

        • 1. Re: Javascript for dropdown boxes
          gkaiseril MVP & Adobe Community Professional

          Multiple value selection is only possible with list boxes.

           

          See currentValueIndices for a coding example.

          • 2. Re: Javascript for dropdown boxes
            George_Johnson MVP & Adobe Community Professional

            You can provide a means to copy the selected value into a textbox, and the text box could have one of more previous selections. Exactly what have you tried so far. It would be helpful to know how you've tried to set this up and what script you've tried.

            • 3. Re: Javascript for dropdown boxes
              Markh1234 Level 1

              Thanks for taking the time out to reply to my post,

               

              I'm not to worried about making 2 selections from a dropdown box, at the moment I can't even do one.

               

              I've a drop down box called "Entrance barrier 1", in the drop downbox box I have 4 or 5 drop downs.

              When I select one of the drop downs I would like it to copy to a text box called "extra site hazards".

              I've created my form on Adobe acrobat pro11.

              I've tried various JavaScript but they don't appear to work. Would you be able to show me an example of what i'm

              trying to do using my names? I'm a new to java so it's baby steps for me! Once my forms completed I'm using my

              Andriod phone to fill out my form using a mobile version of Adobe. Would this change my script?

               

              Many thanks in advance.

               

              MArk

              • 4. Re: Javascript for dropdown boxes
                gkaiseril MVP & Adobe Community Professional

                The example provided will populate if one item is selected or multiple items are selected.

                 

                Since mobile devices depend upon apps and not full programs and apps do not have all the features that a full program has, you will have to test the form on a computer and the mobile device so you can tell if the code works in a full support environment and then if it will work in a limited environment. Also apps are constantly be updated so there is no way to tell when support for some feature has been added.

                 

                The simplest way is to put a calculation in then text box to set the text box equal to the drop down box.

                 

                event.value = "";

                var oField = this.getField("Entrance barrier 1");

                event.value = oField.value;

                 

                The example code will work with a combobox or listbox and the linked code will work with both types of fields, but only the listbox allows multiple selections.

                 

                When the script is in the text box, one needs to exit the combobox or listbox for it to take effect.

                • 5. Re: Javascript for dropdown boxes
                  Markh1234 Level 1

                  Thanks for your reply,

                   

                  I'll give it ago and let you know.

                   

                  Mark.

                  • 6. Re: Javascript for dropdown boxes
                    Markh1234 Level 1

                    I've given the script a try and I have some progress! Nearly.

                     

                    The only way I can get the script to take affect is by entering it in the Custom format script box, is this correct? When I do attempt to select a drop down item, it only appears to copy over the same drop down item in to the text box, regardless of selection.

                    When I attempt to write in the text box after making this selection the drop down text disappears out of the text box.

                     

                    Any Ideas?

                     

                    Thanks for your patients

                     

                    Mark

                    • 7. Re: Javascript for dropdown boxes
                      gkaiseril MVP & Adobe Community Professional

                      It will work in the custom calculation field, but you need to exit the combo box after the selection for the change to take effect.

                       

                      You can also use the custom key stroke but you need to do more setting of properties to have the selection take effect immediately.

                       

                       


                      • 8. Re: Javascript for dropdown boxes
                        Markh1234 Level 1

                        Thanks very much for your help. That scrip worked as I wanted and it works on my mobile device, which is what I wanted.

                         

                        Thanks