1 Reply Latest reply on Mar 24, 2017 2:28 PM by gkaiseril

    Dropdown Field populated by another Dropdown Field

    Azzarrel Level 1

      I have 2 dropdown Fields.

      One Field has x Options. The other field has no available options by deafault, but should get different options based on the value of field1.

       

      Currently I wrote this script, but it isn't quite working as intended

       

      this.getField("Field2").clearItems(); //deletes anything in field2
      
      if (this.getField("Field1").value != "") // Proceed to check different options only if field1 isn't empty in the first place
      
      {  
          if (this.getField("Field1").value == "Option A") // Is the value of Field1 "OptionA"
      
          {  
               values = [" A", "B", "C", "D"]; // Initialize array with possilbe choices
               this.getField("Field2").setItems(values) //Add choices to the dropdown field "Field2" 
      
          }  
          if (this.getField("Field1").value == "Option B") //repeat for option b   
      
          {  
               values = [" D", "E", "F", "G"];  
               this.getField("Field2").setItems(values)  
          }  
      // Add as many more Options as you want. 
      } 
      

      Right now Field2 is populated with the right Items, but due to the problem that this script is getting executed with every new tick, the list gets cleared and re-populated over and over again, prohibiting me of selecting anything but the first value of my List in Field2.

      What I need would be some condition, so my script only runs once when Field1 changes it's value.

       

      Keep in mind that I am not an expert to javascript. I worked with Java before, but I neither have much expierience in Javascript nor with Acrobat DC.