1 Reply Latest reply on Apr 22, 2014 4:19 PM by George_Johnson

    Vlook up fonction

    mtroch

      I have a problem that for some people is easy to resolve.

      Problem:

      I have 2 fields in a pdf file.

      the 1ste field is a selection field. named "Categorie"

      With that information the second field gives a result. "categorie found"

      Example:

      CAT1 = 20 €

      CAT2 = 22 €

      CAT3 = 22 €

      CAT4 = 25 €

      CAT5 = 29 €

       

      So When I select CAT2 in filed 1 the second field gives me 22€

      When I select CAT5 in filed 1 the second field gives me 29€

       

      How can I create a script to do this action automaticaly?

       

      It works like the Vllokup formula in excel

       

      Thankx

        • 1. Re: Vlook up fonction
          George_Johnson MVP & Adobe Community Professional

          Here's what the custom calculation script in the second field could look like:

           

          // Custom calculate script

          (function () {

           

              // Set up the lookup table as an object

               var oLookup = {

                   "-- Select an item --" : "",

                   "CAT1": "20 €",

                   "CAT2": "22 €",

                   "CAT3": "22 €",

                   "CAT4": "25 €",

                   "CAT5": "29 €"

               };

           

              // Get the value of the dropdown/listbox

               var val = getField("Categorie").valueAsString;

           

              // Set this field's value based on the value of the other field

               event.value = oLookup[val] || "Unknown";

           

          })();

           

           

          You might want to replace "Unknown" with a blank string ("") or something else. Whatever you specify there will be what the field gets set to when the selected item is not in the lookup object.

           

          That first item in the object ("--Select an item --") is just there do demonstrate a common situation when using dropdowns. Such an item will be added to provide instructions to the user and prevent a valid selection from being made initially.