2 Replies Latest reply on Apr 20, 2012 9:23 PM by AustinCK

    How to autopopulate a text field with unique data from multiple data sets

    AustinCK

      Hi,

       

      I'm a laboratory manager in charge of a hospital project which will be using pdf forms to send and receive data from our end users across the city. I need help with the last part of our pdf form, specifically with a js that will do a bit of text-field autopopulation magic. This, unfortunately, is a beyond what I have taught myself about pdf js functionality.a

       

      The problem:

      I need to provide my end users with a text field containing a set of data [A, B, C, D, E, F ...] and the total items in this set [tot#]. The end user needs this information as part of the implementation of this particular laboratory machine.

       

      The particulars

      When the end user asks for an experiment to be run, we must specify some pieces of data to help them interpret the results. These are constructed as panels which contain discrete data elements.

       

      For example - One experiment may use two panels, Panel#1 and Panel #2. Panel #1 includes the items A, B, D, E, Panel #2 includes the items A, B, C, F, G.

       

      Thus, the panels may share some of the same items, but, I only want the unique members to be displayed in the text field. If I make a drop down box or checkboxes with the panels, I want to  be able to select the panels that we ran and (in this example) have the text field display only the unique items among all the panels that were used:

       

      textfield outpute = A, B, C, D, E, F, G - 7 total.

       

      Any assistance from the pdf community would be very much appreciated.

       

      Thanks!

        • 1. Re: How to autopopulate a text field with unique data from multiple data sets
          try67 MVP & Adobe Community Professional

          I'm going to give you a generic piece of code that should help you achieve what you need.

          Basically, it shows how to take several arrays of strings (3 in this case), and combine them to a single array with only unique items.

           

          var arr1 = ["A", "B", "C"];

          var arr2 = ["D", "A", "B"];

          var arr3 = ["B"];

           

          var combinedArr = arr1.concat(arr2).concat(arr3);

          combinedArr.sort();

          for (var i=combinedArr.length-1; i>=1; i--) {

              if (combinedArr[i]==combinedArr[i-1]) {

                  combinedArr.splice(i,1);

              }

          }

           

          After this runs, combinedArr equals ["A","B","C","D"].

          • 2. Re: How to autopopulate a text field with unique data from multiple data sets
            AustinCK Level 1

            Thanks for that help.

             

            I should have made it more apparent that I'm very new to scripting and I'm

            not a programmer by trade. I have a few questions before modifying the code

            you kindly provided.

             

            1) Where should I embed this script? Within the 'selection change' area of

            my listbox?

            2) Can I replace the term 'arr' with the names of the various items in my

            listbox or should I put 'arr#' as the output value for each term?

            3) Will this script find and display the unique values when a user selects

            multiple items in my listbox?

            4) How does the script know where to output the unique members of the

            combined set?

             

            I appreciate your patience with me.

             

            ck