10 Replies Latest reply on Dec 21, 2017 5:52 AM by jonathanc1264

    multiple drop down auto populate diffrent field?

    jonathanc1264 Level 1

      I am currently working on a project where I have 6 different dropdown lists all with the same information that would auto populate the corresponding field next to them.

      I obviously am doing something wrong because I can not get each dropdown list and corresponding field to act on their own. What I end up with is being able to control only 1 at a time or all of them. If you look at my small sample code below maybe you can see what I am doing wrong. Any help would be greatly appreciated.

       

      var DepData={"Code Blue Elevator":{contact: "Your Department Chief"},
                             "Lab":{conatact: "Your Department Chief"},
                              };
                               function SetFieldValues(cDeptName)
                               {
                               this.getField("DeptContact").value = DeptData[cDeptName].contact;
                               }
      

       

       

      [Edited by Mod.: Code layout fixed]

        • 2. Re: multiple drop down auto populate diffrent field?
          Thom Parker Adobe Community Professional

          In the SetFieldValues() function, the target field name is hard coded. This needs to be set differently for each dropdown, because they each set a different text field.

           

          There are a couple of ways to do this.

          1. Include the target field name as a function input

          2. Automatically generate the target field name from the name of the current field.

           

          I like #2 best because it reduces the amount of work I have to do. but it requires the fields and named in a consistent fashion that lends itself to this process.  For example "DropDown1" goes to "TextField1". 

          • 3. Re: multiple drop down auto populate diffrent field?
            jonathanc1264 Level 1

            no sorry just a typo couldn't copy and paste the script so I re typed some of it.

            • 4. Re: multiple drop down auto populate diffrent field?
              jonathanc1264 Level 1

              I'm not the best at script but I think I understand. is there any way you could give me an example of how to write that in code?

              • 5. Re: multiple drop down auto populate diffrent field?
                Thom Parker Adobe Community Professional

                The easy method is to just include the name in the code

                Here is a redo of your set function

                 

                                        function SetFieldValues(cDeptName, cTargetField)

                                        {

                                        this.getField(cTargetField).value = DeptData[cDeptName].contact;

                                        }

                 

                Now you're Commit (keystroke) script on the dropdown should include something like this

                 

                SetFieldValues(event.value, "TextField1");

                 

                Of course the "TextField1" needs to actually be the name of the target field on your form.

                • 6. Re: multiple drop down auto populate diffrent field?
                  jonathanc1264 Level 1

                  Alright so I am still able to do just about the same thing and still getting stuck.

                  Imagine I have a 6 fields on the left and 6 fields on the right. All drop down lists on the left are named AppAuth1, AppAuth2, etc.. All the way to 6. Then in the same format on the right named  DeptContact1, ... all the way to DeptContact6. no matter how I play with the code I can always get the first dropdown list to produce the correct information into the DeptContact1 field. Now when I try to alter the code for AppAuth2 to equal DeptContact2 and so forth all the way down it never works. I have no idea how to proceed. is there any way to show me how this would look in code? as for the custom Keystroke script I am using the following code below.

                  {

                  if(event.value == " ")

                  this.resetForm(["DeptContact1"];

                  else SetFieldValues(event.value, "DeptContact1");

                  }

                  • 7. Re: multiple drop down auto populate diffrent field?
                    Thom Parker Adobe Community Professional

                    Get rid of the the resetForm line.

                     

                    What are the curly braces for? is there more code?

                     

                    Change it to this for the the AppAuth2 dropdown

                     

                    if(event.value != " ")

                          SetFieldValues(event.value, "DeptContact2");

                     

                    Did you change the SetFieldValues Function? And delete any previous versions of it?

                     

                    Have you looked in the Console Window for Errors?  Please do this before posting again.

                    Here is a video on using the Console:

                    The Acrobat JavaScript Console Window - YouTube

                    • 8. Re: multiple drop down auto populate diffrent field?
                      jonathanc1264 Level 1

                      I figured it out.... see below if anyone else ever has this issue.

                      So for each dropdown box I added the following code below to the format tab "Create and Edit JavaScripts" changing drobox1 to dropbox2 and text1 to text 2 and so on and so forth. I also named it dropbox1 and text1 so it is easy for someone to understand what is what.

                       

                      event.value = this.getField ("dropbox1").value;

                      if (!event.willCommit)

                      {this.getField ("text1".value=event.changeEX;}

                      • 9. Re: multiple drop down auto populate diffrent field?
                        Thom Parker Adobe Community Professional

                        You say you put this in the Format event? Or do you mean the Keystroke event.

                         

                        So the first line of code does nothing.  It sets the appearance value of the drop-down to its own value.

                        The second line only has meaning for a keystroke event, which is what you must be talking about since you're using the event.changeEx property which only has value in the Keystroke event.

                         

                        So what you are saying is that you hand coded each field to do what I was telling you to do in the previous posts.

                         

                        For other people read this, do not use the code posted by jonathanc1246, this is not the right way to go.

                        • 10. Re: multiple drop down auto populate diffrent field?
                          jonathanc1264 Level 1

                          Thom Parker,

                          I'm not sure you picked up on this but I do not write code for a living... I had a task that needed completing so I reached out on this forum hoping for a solution to the problem I had. Please do not take your inability to explain in a helpful way as any kind of insult to your intelligence. I literally scoured the internet for a solution to my problem. In my mind if it works then there is no "wrong" way to go. Maybe you should make another video just for the purpose of explaining why my solution to the problem is not the right way to go and I would happily watch it. I love to learn and to help others so when you respond to the next person to try and help please keep in mind that their working knowledge is probably not at your level hence the reason they are reaching out for assistance.