0 Replies Latest reply on Sep 4, 2014 10:43 AM by Sidneythecat

    Combo-box to populate text field depending on selected item from list.

    Sidneythecat Level 1

      I recently posted the question below on the AcrobatUsers.com and I received an answer (below) but could not get it to work. I'm apparently missing some key information in writing the Javascript properly. In my original question, I didn't mention that I have a total of five different combo boxes that are triggered by the user clicking a radio button to bring up the combo box with the list of items that is specific to that radio button. I'm not sure if that would have anything to do with this solution not working and I'm totally at a loss to figure it out. Maybe there is an easier solution - which for me is always my preference. Any help would be appreciated and please include as much information in the way of detailed steps because I'm really pretty new at this. Thanks!


      Question:


      I have a combo-box (drop down) that has 10 possible selections. If the user selects items 1, 2, 3 or 4 from drop-down, I need the selection to populate text field 1 only and hide text field 2, text field 3, text field 4, etc. If they choose any of the remaining selections in the drop-down box, I need those selections to populate text field 2, show text fields 3, 4, etc. and hide text field 1. I have the array and indexes set up in the combo-box. I'm new to JavaScript so not sure if these would be formatting scripts, calculation scripts, validation scripts or a combination of several of those. Or if this is even possible. Any help would be appreciated. Thanks.


      Answer I received:


      Create your fields, then bring up the field properties for your drop down control and go to the "Validate" tab. Select to create a custom validation script and use this:

       

      var fGroup = [ "Text2", "Text3", "Text4" ];

      if (event.value == "1" || event.value == "2" || event.value == "3" || event.value == "4") {

          var f = this.getField("Text1");

          f.display = display.visible;

          f.value = event.value;

          for (var i in fGroup) {

              this.getField(fGroup[i]).display = display.hidden;

          }

      }

      else {

          this.getField("Text1").display = display.hidden;

          for (var i in fGroup) {

              this.getField(fGroup[i]).display = display.visible;

          }

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

      }

      You will of course have to modify the script to match your specific form. The important steps are to change fGroup to include all the fields that you want to hide or show based on the selection (e.g. fields 2...10 or 2...4 as in my example). You also need to change the condition where you test if one of the first four list elements are selected.