12 Replies Latest reply on Jul 23, 2010 10:51 AM by jbash83

    Updating Combo Boxes from Text Boxes

    jbash83

      I am trying to code a PDF that will have a list of currency abreviations in five different text boxes, and have it so that those five text boxes populate a series of combo boxes.

       

      For Example, my five text boxes have

      USD in Currency.0

      GBP in Currency.1

      YEN in Currency.2

      CHF in Currency.3

      ZAR in Currency.4

       

      now I want to write some code that pulls the values from those 5 text boxes and and puts my five currencies in a combo box. So far I have patched together the following code:

       

       

      var a = this.getField("Currency.0").value
      var b = this.getField("Currency.1").value
      var c = this.getField("Currency.2").value
      var d = this.getField("Currency.3").value
      var e = this.getField("Currency.4").value
      var list = new Array(a,b,c,d,e); // define array of items for combo boxes
      if( event.willCommit )
      {
         if(event.value == "")
           this.resetForm([a,b,c,d,e]);
         else
          SetFieldValues((list));
      }

       

      My problem is if I change GBP in Currency.1 to DKK, the combo box won't update or change at all. I need this to be dynamic, and have tried all manner of refresh() & clear() commands. I have a feeling I'm very close but can't get over this last hurdle. (BTW I know the if() thing is poorly coded but thats all I cound get to work). Thanks in advance to anyone who can solve this.

        • 1. Re: Updating Combo Boxes from Text Boxes
          try67 MVP & Adobe Community Professional

          resetForm takes an array of field NAMES, not field VALUES...

          Have another look at the examples in the reference files.

          • 2. Re: Updating Combo Boxes from Text Boxes
            jbash83 Level 1

            I removed the reset.form line and just went to what (apparantly) was working. However, I still cannot change the field Currency.0 and have the combo box update. Very frustrating. Is there a line I should add to make this happen?

             

             

            var a = this.getField("Currency.0").value
            var b = this.getField("Currency.1").value
            var c = this.getField("Currency.2").value
            var d = this.getField("Currency.3").value
            var e = this.getField("Currency.4").value
            var list = new Array(a,b,c,d,e); // define array of items for combo boxes
            if( event.willCommit )
            {
               if(event.value == "")
                 SetFieldValues((list));
               else
                SetFieldValues((list));
            }

            • 3. Re: Updating Combo Boxes from Text Boxes
              try67 MVP & Adobe Community Professional

              Where do you define SetFieldValues ? And why the double parentheses? Also, I

              would suggest changing the names of your text boxes as Acrobat uses the dot

              notation you used (field.1, field.2, field.3, etc.) to create copies of the

              same field.

              • 4. Re: Updating Combo Boxes from Text Boxes
                jbash83 Level 1

                trv: I'm not sure about the SetFieldValues. I'm just getting my feet wet here. The double parentheses was likely left over from my trial and error method of trying to fix this. To confuse things even more I have tried this code:

                 

                var a = this.getField("Currency.0").value
                var b = this.getField("Currency.1").value
                var c = this.getField("Currency.2").value
                var d = this.getField("Currency.3").value
                var e = this.getField("Currency.4").value
                var list = new Array(a,b,c,d,e); // define array of items for combo boxes
                var a0 = this.getField("UnitsA.0"); // get combo box
                a0.setItems((list))

                 

                and does fill the field UnitsA.0, however if I run it as a keystroke script it sends my computer into overdrive and flashes a keyboard and hourglass. I usually have to ctrl+alt+del. If I run it as a custom calculation, I can't actually select any of my updated values.

                 

                I'm going to rename the fields now and see what else I can do get this working

                • 5. Re: Updating Combo Boxes from Text Boxes
                  try67 MVP & Adobe Community Professional

                  What event needs to trigger this code?

                  • 6. Re: Updating Combo Boxes from Text Boxes
                    jbash83 Level 1

                    Whenever I change one of the currency fields (now currency1 instead of currency.0)

                    I want the combo box to change.


                    • 7. Re: Updating Combo Boxes from Text Boxes
                      try67 MVP & Adobe Community Professional

                      Try placing the code in the validate event of each field.

                      • 8. Re: Updating Combo Boxes from Text Boxes
                        jbash83 Level 1

                        Combo box is blank, no values listed.

                        • 9. Re: Updating Combo Boxes from Text Boxes
                          try67 MVP & Adobe Community Professional

                          Any errors in the console? Make sure the option to display the console on

                          errors and warnings is ticked under Edit - Preferences - JavaScript.

                          • 10. Re: Updating Combo Boxes from Text Boxes
                            jbash83 Level 1

                            No errors, and nothing ever appears in the text box when I use validation. I tried both scripts I posted above. I did enable the error option in preferences before testing.

                            • 11. Re: Updating Combo Boxes from Text Boxes
                              jbash83 Level 1

                              I found this post an it mentioned document level scripts. Is there a way to do what I want to do (automatically refresh the combo box when a text field changes) using that method?

                               

                               

                              http://forums.adobe.com/message/2850045#2850045

                               

                              edit: this does work, however combo box only refreshes every time the document is opened. Anyone have any thoughts on how to make it refresh when a text field is changed?

                               

                              btw Thx try67 for you continued help

                               

                              Message was edited by: jbash83

                              • 12. Re: Updating Combo Boxes from Text Boxes
                                jbash83 Level 1

                                I believe I have stumbled upon a solution:

                                 

                                Document Level Script:

                                 

                                function combo1()
                                {var a = this.getField("Field1").value
                                var b = this.getField("Field2").value
                                var c = this.getField("Field3").value
                                var d = this.getField("Field4").value
                                var e = this.getField("Field5").value
                                var list = new Array(a,b,c,d,e);
                                var combo1 = this.getField("combo1");
                                combo1.setItems(list);
                                }
                                combo1()

                                 

                                Text Box Keystroke Scripts

                                 

                                Field1 Keystroke Script:

                                combo1()

                                Field2 Keystroke Script:

                                combo1()

                                Field3 Keystroke Script:

                                combo1()

                                Field4 Keystroke Script:

                                combo1()

                                Field5 Keystroke Script:

                                combo1()

                                 

                                I will test further. Posted because other people's solutions have been tremendously helpful in learning how to write JS. Thank you all.