9 Replies Latest reply on May 30, 2016 12:53 AM by pdfUser1

    Drop down A to populate Drop down B, C, and D

    pdfUser1 Level 1

      I have several drop downs. Drop down A, B, C, D and so on. All the drop downs have the same names in them but different values. For instance, drop down A has a list of names and export value is the person's address. Drop down B has the same list of names but export values are the person's SSN's. Drop down C has the same names but export values are $15 or $23 etc (their hourly pay rate). And so forth for the additional drop downs.

       

      What I would like to do is when I select the person's name from Drop down A  then all the other drop downs will show that name but will return that drop down's value automatically into the text field connected to showing the results for that drop down. Text fieldA would show the value of Drop down A. Text fieldB would show the value for drop down B. Text fieldC would show the value for drop down C (and so on).

       

      Is this possible? Could someone help me out with an example script that I can try out? That would help greatly. Thanks guys.

        • 1. Re: Drop down A to populate Drop down B, C, and D
          try67 MVP & Adobe Community Professional

          These are two separate issues. The first is copying the value from one drop-down to others. The second is copying the (export) values from the drop-downs to text fields.

          Both are relatively simple if all of the values are the same.

          To copy the value of Dropdown A to Dropdown B, C and D you can use this code as its custom validation script (make sure you tick the option to commit the selected value immediately):

           

          this.getField("Dropdown B").value = event.value;

          this.getField("Dropdown C").value = event.value;

          this.getField("Dropdown D").value = event.value;

           

          To copy the value of Dropdown A to Text A use this script as the custom calculation script of the latter:

          event.value = this.getField("Dropdown A").value;

          • 2. Re: Drop down A to populate Drop down B, C, and D
            pdfUser1 Level 1

            Thank you for trying to help. unfortunately, I couldn't get the script to work the way I would like. I got the first part to function and populate the name of the person into all the drop downs. But, not the information that is in each drop down. For instance, all the drop downs have the same names of the people but different information. Drop downA has their addresses. Drop downB has their social security numbers. Drop downC has their hourly pay rate.

             

            What I am trying to do is make a name selection from drop downA then that person's address would populate into textA field. Then that person's SSN would populate into textB field from drop downB. Then that person's hourly pay rate would populate into textC from drop downC, etc. How can I do that?

            • 3. Re: Drop down A to populate Drop down B, C, and D
              try67 MVP & Adobe Community Professional

              Why are you using drop-downs for this? Why not simply use a text field and populate it with the correct values for each selection?

              • 4. Re: Drop down A to populate Drop down B, C, and D
                pdfUser1 Level 1

                I really don't know what the best approaches are in javascripting and form building. I'd like to see what you're referring to by your suggestion. How would I do that?

                 

                The main reason I was using these drop downs are originally I had separate info in each that I would manually select each from each drop down. Then I thought to ask is there a better and easier way. That's when I posted my question.

                 

                How would I have all the info do as you suggest? It surely sounds more logical than my approach. But, I wouldn't know how to implement it. Would you have an example I could try out? Thanks.

                • 5. Re: Drop down A to populate Drop down B, C, and D
                  try67 MVP & Adobe Community Professional

                  Well, the basic code is not that complicated.

                  It would be something like this (as the custom validation of the drop-down field):

                   

                  if (event.value == "John") {
                      this.getField("Address").value = "123 Main Street";
                      this.getField("City").value = "New York";
                      this.getField("State").value = "New York";
                  } else if (event.value == "Mary") {
                      this.getField("Address").value = "5 Apple Street";
                      this.getField("City").value = "Seattle";
                      this.getField("State").value = "Washington";
                  }
                  // etc/
                  else {
                      this.getField("Address").value = "";
                      this.getField("City").value = "";
                      this.getField("State").value = "";
                  }
                  

                   

                   

                  I've actually developed a tool that allows you to set up such a task without having to write any code. If you're interested you can purchase it from here:

                  Custom-made Adobe Scripts: Acrobat -- Populate Fields From Dropdown

                  • 6. Re: Drop down A to populate Drop down B, C, and D
                    gkaiseril MVP & Adobe Community Professional

                    I would look at different way so I am "working smarter not harder".

                     

                    One can create a data object that has each employees unique name, their SSN and their PayRate for the element entry and values. This data object can be used to populate the drop down and when a change for an employee happens or a new employee is added or an existing employee is removed, there is only one place that has to be edited.

                     

                    There is the drop down list for the names with a custom keystroke script of:

                     

                    if( event.willCommit ) {
                        if(event.value == " ") this.resetForm(["SSN","PayRate"]);
                        else SetFieldValues(event.value);
                    }

                     

                    Then there are 2 read only text fields, SSN with a format of SSN and PayRate with format of number and 2 decimal places.

                     

                    Now one needs to create a document level script to initialize the data structure, populate the drop down list, and execute the custom keystroke function.

                     

                    // Place all pre-population data into a single data structure
                    var DeptData = {
                    "Able, Allen": { SSN: "101-01-1010", PayRate: 25},
                        "Baker, Bil": { SSN: "202-02-2020", PayRate: 35},
                        "Charles, Chuck": { SSN: "303-03-3030", PayRate: 45}
                        }; // end of data structure

                    // populate dorp down names;
                    var MyItems = new Array(" ")
                    for(var i in DeptData)
                    {
                    MyItems[MyItems.length] = i;
                    }
                    this.getField("A").setItems(MyItems);

                    function SetFieldValues(cDeptName) {
                        // Populate fields with values from the Department Data Object
                        this.getField("SSN").value = DeptData[cDeptName].SSN;
                        this.getField("PayRate").value = DeptData[cDeptName].PayRate;
                        }

                     

                    This based on the tutorial Changing another field with combo box (drop down) selection by Thom Parker

                     

                    Link to a working sample .

                    • 7. Re: Drop down A to populate Drop down B, C, and D
                      pdfUser1 Level 1

                      Thanks for sending the link. I found it very interesting and way beyond my level of scripting understanding but I'll play around with it to learn. A few question come up though.

                       

                      Like. How would I have multiple lines in some of the text fields, for example the complete address being in one field. I had a script I got from the acrobat users forum that would enable me to do that. I remember all I had to do was put a comma at where I wanted to split the entry then when I selected the name it would come out in the text field as three (or more) lines.

                       

                      How would I be able to enter info directly into the drop down(s), not into the coding. Mainly, for the user benefit and because people come and go, prices change etc. And, assuming most people don't have the acrobat pro or want to learn javascript, I just want to make it easy for the users. I also had a script that would allow me to do so. I would type into the drop down after clicking the arrow to open it. I could type a name or whatever into the field then press the Return key and a window would pop open where I could enter text or a number or address and using commas I would see three separate lines.

                       

                      If you could write something like what I've described I would be glad to compensate you for your time. I don't have a large budget but I would be more than happy to pay you. I think others would too, if they had a script to do this.

                       

                      Anyway, you've been very generous with your time and help. Thank you very much. I really like learning javascript.

                      • 8. Re: Drop down A to populate Drop down B, C, and D
                        gkaiseril MVP & Adobe Community Professional

                        As to creating multiple lines, search for the answer or learn how to add the special characters for a new line. This in the free Adobe Acrobat SDK documentation.

                         

                        Because you are asking for so much more information, I do not think Acrobat is proper tool to create what you are looking for. It probably could hold the data for a hundred employees but it is not very scalable and if this is an HR system it is missing a lot of controls and reporting requirements.

                         

                        You should consider getting the services of a system analyst to determine what you are trying to accomplish in full and what the best tools to use would be.

                         

                        You could create a number of forms using LiveCycle to directly connect to a DBMS to store and retrieve your data as well as allow any number of reports to be created. There are even low costs DBMS systems that would better meet your needs.

                         

                        This is a user 2 user forum and the majority of responders are not paid. We try to help others with simple issues but your request is just to much to expect to be done for free.

                        • 9. Re: Drop down A to populate Drop down B, C, and D
                          pdfUser1 Level 1

                          Thanks for your time gkaiseril and the food for thought. But, someone got in touch with me and I'm paying him $30 dollars to write the script I'm looking for. I offered to pay in one of my replies. They said it's not complicated and not too much to expect at all and has sent me a sample of the work and at this point it should be done tomorrow. I offered to pay you as well. Oh well.

                           

                          Anyway, acrobat as it turns out is the perfect tool for what I'm creating. There are so many reasons for my choosing it. Firstly, it's cross platform and the list of reasons goes on. It is becoming my first choice as my "go to" app for creating forms and docs. I just need help at times and to learn javascripting a bit more. LiveCycle is out of the question because I'm on a Mac and it would mean changing computer systems.

                           

                          I was a member of the AcrobatUsers forum for a few years and which taught me so much. When I first got the app I didn't know anything about javascript. I'm glad to see many of the people here as well. But, I miss that forum now it's a Read Only site. I hope this site will provide the same opportunities to interact and to learn. It's a bit different here.

                           

                          Anyway, I always appreciate the help I get regardless where it comes from. I want to say thank you to everyone.