10 Replies Latest reply on Feb 12, 2014 11:35 PM by George_Johnson

    One Combo Box, Two Text Boxes

    berocca Level 1

      Hi all, I feel a bit silly for asking this as it should be really simple, right? I have the one combo box, one text box solution down pat. E.g. When the user select a staff member's name from the dropdown, it pre-fills that person's phone number into Textbox1.

       

      I want to add to this so that when a user selects (and I'm using fake details here) "Bob" it pre-fills his phone number in Textbox1 and "bob@bob.com" into Textbox2 simultaneously. Simply cannot find the solution anywhere.

       

      So far I have used the following code (from the net) in Custom Keystroke scripts of the combo box, but how do I expand on this?

       

      (function () {

          // Do nothing if not committed
          if (event.willCommit) return;

          // Set up an array to hold the individual paragraphs of text
          var aQuotes = [];

          // Populate the array with the paragraph text
          aQuotes[0] = "bob phone"
          aQuotes[1] = "sarah phone"
          aQuotes[2] = "linda phone"
          aQuotes[3] = "jerry phone"   
          aQuotes[4] = "mary phone"
          aQuotes[5] = "jessie phone"
         
      // Get the selected item, which is the export value of the selected combo box item
          var item = event.changeEx

          // Display the text corresponding to the selected item in the text field
          getField("ITC Phone").value = aQuotes[item];

      })();

       

       

       

      Cheers guys.

        • 1. Re: One Combo Box, Two Text Boxes
          George_Johnson MVP & Adobe Community Professional

          Like this:

           

          // Custom Keystroke script for combo box (dropdown)

          (function () {

           

              // Do nothing if not committed

              if (event.willCommit) return;

           

              // Set up an array to hold the individual paragraphs of text

              var aQuotes = [];

           

              // Populate the array arrays of phone and email addresses

              aQuotes[0] = ["bob phone", "bob@example.com"];

              aQuotes[1] = ["sarah phone", "sarah@example.com"];

              aQuotes[2] = ["linda phone", "linda@example.com"];

              aQuotes[3] = ["jerry phone", "jerry@example.com"];

              aQuotes[4] = ["mary phone", "mary@example.com"];

              aQuotes[5] = ["jessie phone", "jessie@example.com"];

            

              // Get the selected item, which is the export value of the selected combo box item

              var item = event.changeEx;

           

              // Display the text corresponding to the selected item in the text field

              getField("ITC Phone").value = aQuotes[item][0];

              getField("ITC Email").value = aQuotes[item][1];

           

          })();

           

           

          This code assumes that the export values of the combo box items are 0, 1, 2, 3...

           

          If there are many more items than this the aQuotes array really should be defiined in a document-level JavaScript file if you're concerned about performance and maintainability.

          • 2. Re: One Combo Box, Two Text Boxes
            berocca Level 1

            You legend! Thank you!

            • 3. Re: One Combo Box, Two Text Boxes
              berocca Level 1

              So, I've been trying to use this code but customise it to a slightly different situation, it's not working for me.

               

              I have one dropdown box with 3 items and 10 different text boxes all named differently. I want each item to pre-fill a different selection of text boxes.

               

              So for example: if I select Bob from the Combobox, I want "abcd" to appear in TextBoxes 1, 2, 3 and 4 only.

               

              If I select Sarah from the combobox, I want "abcd" to appear in Textboxes 1 and 5 only. And so on.

               

              I thought that by adding each Textbox at the bottom in the 'getfield' bit and changing the number to the corrosponding Combobox item would do it, but it doesn't. What am I missing??

              • 4. Re: One Combo Box, Two Text Boxes
                George_Johnson MVP & Adobe Community Professional

                Will the text that you want to display ("abcd") always be the same for each item selected and each text field, or will it be different for each itme and each text field? Should the other text fields be cleared if not filled with the text?

                • 5. Re: One Combo Box, Two Text Boxes
                  berocca Level 1

                  Hi George,

                   

                  In this case, the text that is being displayed "abcd" is the same every time. Just the textboxes change.

                  • 6. Re: One Combo Box, Two Text Boxes
                    George_Johnson MVP & Adobe Community Professional

                    Assuming you want the unused text fields to be cleared, the code could be:

                     

                    // Custom Keystroke script for combo box (dropdown)

                    (function () {

                     

                        // Do nothing if not committed

                        if (event.willCommit) return;

                     

                        // Set up an array to hold the individual paragraphs of text

                        var aQuotes = [];

                     

                        // Indicate which text fields should be populated (e.g., 1 = Text1, 4 = Text4, etc.)

                        aQuotes[0] = [1, 2, 3, 4];  // Bob

                        aQuotes[1] = [1, 5];  // Sarah

                        aQuotes[2] = [2, 5, 7, 8, 10];  // Someone else

                     

                        // Get the selected item, which is the export value of the selected combo box item

                        var item = event.changeEx;

                     

                       // Begin by clearing all of the text fields

                        for (var i = 1; i < 11; i += 1) {

                            getField("Text" + i).value = "";

                        }

                     

                        // Populate the fields specified in the array

                        for (var i = 0; i < aQuotes[item].length; i += 1) {

                            getField("Text" + aQuotes[item][i]).value = "abcd";

                        }

                     

                    })();

                     

                     

                    The code assumes the text fields are named Text1, Text2, ...Text10. This could be simplified a bit since you probably don't need to set up numeric export values in this case and if you use hierarchical naming for the text fields (Text.0, Text.1, Text.2, etc.), but you should get the idea.

                    • 7. Re: One Combo Box, Two Text Boxes
                      berocca Level 1

                      Hey, I don't want the unused text fields to be cleared. Info will need to be typed into them, just not anything that can be pre-filled.

                      • 8. Re: One Combo Box, Two Text Boxes
                        George_Johnson MVP & Adobe Community Professional

                        Then just remove that block of code.

                        • 9. Re: One Combo Box, Two Text Boxes
                          berocca Level 1

                          Hey George, I'm finding this quite confusing and had been putting off replying. In reality my text fields are not named Text1, Text2 etc so I was replacing the numbers in the aQuotes[0] = [1, 2, 3, 4]; bit with the actual names of the fields but keep getting syntax errors.

                           

                          I am open to renaming the text boxes, but I am also unclear on whether they should be Text1, Text2, Text3 or Text.0, Text.1, Text.3...

                          • 10. Re: One Combo Box, Two Text Boxes
                            George_Johnson MVP & Adobe Community Professional

                            The code I posted would be for "Text1, Text2, Text3", but you can use any prefix you want, you'd just have to adjust the code to match whatever it is you decide to use.