12 Replies Latest reply on Dec 7, 2013 8:14 AM by Branchard0902

    using value from one form field in another form field

    Branchard0902

      I hope I can accurately describe my problem. Please bear with me

       

      I have a worksheet with a lot of form fields. Mostly text boxes and a few combo boxes.

      I'm using a lot of custom calculation scripts to determine what information auto populates into most of the fields.

      But I'm having problems with one last form field named ORTHOPLANID.

       

      The value it auto populates depends on two other fields. One field is called MEDOOP. The other field is SUPPDENPLANID. I tried using a if/then/else statement for ORTHOPLANID but it's not working. I am guessing it doesn't work b/c the value in the MEDOOP field is generated from an if/then statement so I'm not sure if the script recognizes its value as a true value or not.

       

      Is there another way around this? I'm not sure if I've clearly explained the problem but I hope someone can help

       

      Thanks,

      Brandy

        • 1. Re: using value from one form field in another form field
          George_Johnson MVP & Adobe Community Professional

          It's hard to say without being able to look at the form, but you can begin by confirming that the field calculation order is correct (it's not the same thing as the tab order) and checking to see if any errors are reported in the JavaScript console (Ctrl+J).

          • 2. Re: using value from one form field in another form field
            try67 MVP & Adobe Community Professional

            In principle it's possible to do that. There might be problems with the calculation order, as George indicated, or with the code.

            Can you post the code you're using? Also, open the JS console and make sure there are no errors when you change the value of any field in the file.

            • 3. Re: using value from one form field in another form field
              Branchard0902 Level 1

              I thought I had solved the mystery but I didn't

               

              Ok. The code for MEDOOP is this:

              var a = this.getField("MEDPLANNAME").value;
              if (a == 'SG Bronze 1') event.value = '$6350';
              else if (a == 'SG Bronze 2') event.value = '$6350';
              else if (a == 'SG Bronze 3') event.value = '$6350';
              else if (a == 'SG Silver 1') event.value = '$6350';
              else if (a == 'SG Silver 2') event.value = '$6350';
              else if (a == 'SG Silver 3') event.value = '$6350';
              else if (a == 'SG Silver 4') event.value = '$5000';
              else if (a == 'SG Silver 5') event.value = '$3500';
              else if (a == 'SG Silver 6') event.value = '$6000';
              else if (a == 'SG Silver 7') event.value = '$6350';
              else if (a == 'SG Silver 8') event.value = '$6250';
              else if (a == 'SG Silver 9') event.value = '$6350';
              else if (a == 'SG Silver 10') event.value = '$6350';
              else if (a == 'SG Silver 11') event.value = '$5000';
              else if (a == 'SG Gold 1') event.value = '$2350';
              else if (a == 'SG Gold 2') event.value = '$2000';
              else if (a == 'SG Gold 3 w/HRA') event.value = '$6000';
              else if (a == 'SG Gold 4') event.value = '$6350';
              else if (a == 'SG Gold 5 w/HRA') event.value = '$6350';
              else if (a == 'SG Gold 6') event.value = '$3500';
              else if (a == 'SG Gold 7') event.value = '$5000';
              else if (a == 'SG Gold 8 w/HRA') event.value = '$6000';
              else if (a == 'SG Gold 9') event.value = '$3000';
              else if (a == 'SG Gold 10') event.value = '$4000';
              else if (a == 'SG Gold 11') event.value = '$5000';
              else if (a == 'SG Gold 12') event.value = '$5250';
              else if (a == 'SG Gold 13') event.value = '$4000';
              else if (a == 'SG Gold 14') event.value = '$5000';
              else if (a == 'SG Gold 15') event.value = '$6000';
              else if (a == 'SG Gold 16') event.value = '$4000';
              else if (a == 'SG Platinum 1') event.value = '$2500';
              else if (a == 'SG Platinum 2') event.value = '$1800';
              else event.value = ' ';

               

               

              The code for SUPPDENPLANID is this:

              var a = this.getField("SUPPDENPLANNAME").value;
              if(a == 'Voluntary Dental Plan 1') event.value = 'DEHGVN01';
              else if(a == 'Voluntary Dental Plan 2') event.value = 'DEHGVY02';
              else if(a == 'Voluntary Dental Plan 3') event.value = 'DEHGVN03';
              else if(a == 'Voluntary Dental Plan 4') event.value = 'DEHGVY04';
              else if(a == 'Voluntary Dental Plan 5') event.value = 'DEHGVN05';
              else if(a == 'Non-Voluntary Dental Plan 1') event.value = 'DEHGNN01';
              else if(a == 'Non-Voluntary Dental Plan 2') event.value = 'DEHGNY02';
              else if(a == 'Non-Voluntary Dental Plan 3') event.value = 'DEHGNN03';
              else if(a == 'Non-Voluntary Dental Plan 4') event.value = 'DEHGNY04';
              else if(a == 'Non-Voluntary Dental Plan 5') event.value = 'DEHGNN05';
              else if(a == 'Non-Voluntary Dental Plan 6') event.value = 'DEHGNY06';
              else if(a == 'Non-Voluntary Dental Plan 7') event.value = 'DEHGNN07';
              else if(a == 'Non-Voluntary Dental Plan 8') event.value = 'DEHGNN08';
              else if(a == 'Non-Voluntary Dental Plan 9') event.value = 'DEHGNN09';
              else if(a == 'Non-Voluntary Dental Plan 10') event.value = 'DEHGNY10';
              else event.value = ' ';


              The field I'm having problems with is called SUPPORTHOPLANID. It's code is this:

               

              var a = this.getField("SUPPDENPLANID").value;
              var b = this.getField("MEDOOP").value;
                   if(a == 'DEHGNY02' && b == '$1800')event.value = 'DEHGPA01';
              else if(a == 'DEHGNY02' && b == '$2000')event.value = 'DEHGPB01';
              else if(a == 'DEHGNY02' && b == '$2350')event.value = 'DEHGPC01';
              else if(a == 'DEHGNY02' && b == '$2500')event.value = 'DEHGPD01';
              else if(a == 'DEHGNY02' && b == '$3000')event.value = 'DEHGPE01';
              else if(a == 'DEHGNY02' && b == '$3500')event.value = 'DEHGPF01';
              else if(a == 'DEHGNY02' && b == '$4000')event.value = 'DEHGPG01';
              else if(a == 'DEHGNY02' && b == '$5000')event.value = 'DEHGPH01';
              else if(a == 'DEHGNY02' && b == '$5250')event.value = 'DEHGPJ01';
              else if(a == 'DEHGNY02' && b == '$6000')event.value = 'DEHGPK01';
              else if(a == 'DEHGNY02' && b == '$6250')event.value = 'DEHGPL01';
              else if(a == 'DEHGNY02' && b == '$6350')event.value = 'DEHGPM01';
              else if(a == 'DEHGNY04' && b == '$1800')event.value = 'DEHGPA02';
              else if(a == 'DEHGNY04' && b == '$2000')event.value = 'DEHGPB02';
              else if(a == 'DEHGNY04' && b == '$2350')event.value = 'DEHGPC02';
              else if(a == 'DEHGNY04' && b == '$2500')event.value = 'DEHGPD02';
              else if(a == 'DEHGNY04' && b == '$3000')event.value = 'DEHGPE02';
              else if(a == 'DEHGNY04' && b == '$3500')event.value = 'DEHGPF02';
              else if(a == 'DEHGNY04' && b == '$4000')event.value = 'DEHGPG02';
              else if(a == 'DEHGNY04' && b == '$5000')event.value = 'DEHGPH02';
              else if(a == 'DEHGNY04' && b == '$5250')event.value = 'DEHGPJ02';
              else if(a == 'DEHGNY04' && b == '$6000')event.value = 'DEHGPK02';
              else if(a == 'DEHGNY04' && b == '$6250')event.value = 'DEHGPL02';
              else if(a == 'DEHGNY04' && b == '$6350')event.value = 'DEHGPM02';
              else if(a == 'DEHGNY06' && b == '$1800')event.value = 'DEHGPA01';
              else if(a == 'DEHGNY06' && b == '$2000')event.value = 'DEHGPB01';
              else if(a == 'DEHGNY06' && b == '$2350')event.value = 'DEHGPC01';
              else if(a == 'DEHGNY06' && b == '$2500')event.value = 'DEHGPD01';
              else if(a == 'DEHGNY06' && b == '$3000')event.value = 'DEHGPE01';
              else if(a == 'DEHGNY06' && b == '$3500')event.value = 'DEHGPF01';
              else if(a == 'DEHGNY06' && b == '$4000')event.value = 'DEHGPG01';
              else if(a == 'DEHGNY06' && b == '$5000')event.value = 'DEHGPH01';
              else if(a == 'DEHGNY06' && b == '$5250')event.value = 'DEHGPJ01';
              else if(a == 'DEHGNY06' && b == '$6000')event.value = 'DEHGPK01';
              else if(a == 'DEHGNY06' && b == '$6250')event.value = 'DEHGPL01';
              else if(a == 'DEHGNY06' && b == '$6350')event.value = 'DEHGPM01';
              else if(a == 'DEHGNY10' && b == '$1800')event.value = 'DEHGPA01';
              else if(a == 'DEHGNY10' && b == '$2000')event.value = 'DEHGPB01';
              else if(a == 'DEHGNY10' && b == '$2350')event.value = 'DEHGPC01';
              else if(a == 'DEHGNY10' && b == '$2500')event.value = 'DEHGPD01';
              else if(a == 'DEHGNY10' && b == '$3000')event.value = 'DEHGPE01';
              else if(a == 'DEHGNY10' && b == '$3500')event.value = 'DEHGPF01';
              else if(a == 'DEHGNY10' && b == '$4000')event.value = 'DEHGPG01';
              else if(a == 'DEHGNY10' && b == '$5000')event.value = 'DEHGPH01';
              else if(a == 'DEHGNY10' && b == '$5250')event.value = 'DEHGPJ01';
              else if(a == 'DEHGNY10' && b == '$6000')event.value = 'DEHGPK01';
              else if(a == 'DEHGNY10' && b == '$6250')event.value = 'DEHGPL01';
              else if(a == 'DEHGNY10' && b == '$6350')event.value = 'DEHGPM01';
              else if(a == 'DEHGVY02' && b == '$1800')event.value = 'DEHGPA03';
              else if(a == 'DEHGVY02' && b == '$2000')event.value = 'DEHGPB03';
              else if(a == 'DEHGVY02' && b == '$2350')event.value = 'DEHGPC03';
              else if(a == 'DEHGVY02' && b == '$2500')event.value = 'DEHGPD03';
              else if(a == 'DEHGVY02' && b == '$3000')event.value = 'DEHGPE03';
              else if(a == 'DEHGVY02' && b == '$3500')event.value = 'DEHGPF03';
              else if(a == 'DEHGVY02' && b == '$4000')event.value = 'DEHGPG03';
              else if(a == 'DEHGVY02' && b == '$5000')event.value = 'DEHGPH03';
              else if(a == 'DEHGVY02' && b == '$5250')event.value = 'DEHGPJ03';
              else if(a == 'DEHGVY02' && b == '$6000')event.value = 'DEHGPK03';
              else if(a == 'DEHGVY02' && b == '$6250')event.value = 'DEHGPL03';
              else if(a == 'DEHGVY02' && b == '$6350')event.value = 'DEHGPM03';
              else event.value = ' ';

               

               

              When I started testing it, it should have put DEHGPM03 but it was blank. When I went into the code and just looked at it and closed it, it populated it then. But that was in the "edit" mode. Not in "production" mode, so to stay.

               

              Where am I going wrong????

               

               

               


              • 4. Re: using value from one form field in another form field
                try67 MVP & Adobe Community Professional

                The code won't work in the Preview mode, if that's what you mean. You have to test it outside of the Form Edit mode entirely.

                • 5. Re: using value from one form field in another form field
                  Branchard0902 Level 1

                  I have tested it outside the Form Edit mode. The very first scenario I tested should have resulted in DEHGPM03 being in the SUPPORTHOPLANID field but it wasn't. I then went into edit mode and looked at the code for this field and when i closed the code section (but still in edit mode), it populated it. But it won't populate in normal viewing/user mode.

                  • 6. Re: using value from one form field in another form field
                    try67 MVP & Adobe Community Professional

                    Where did you place the code, exactly? Can you share the file?

                    • 7. Re: using value from one form field in another form field
                      gkaiseril MVP & Adobe Community Professional

                      Nested if statements can be hard to read and can be hard to code. I would look at using the "switch" statement. You can test for the actual value of a field or test if an expression or comparison evaluates to true or false.

                       

                      For assigning currency values to a field, I would assign a number and let the formatting of the field apply needed currency symbol and displayed decimal places.

                       

                      var a = this.getField("MEDPLANNAME").value;
                      switch(this.getField("MEDPLANNAME").value) {

                      case 'SG Platinum 2':
                      event.value = 1800;
                      break;

                      case 'SG Gold 2':
                      event.value = '$2000';
                      break;

                      case 'SG Platinum 1':
                      event.value = '$2500';
                      break;

                      case 'SG Gold 1':
                      event.value = '$2350';
                      break;

                      case 'SG Gold 9':
                      event.value = '$3000';
                      break;

                      case 'SG Silver 5'
                      case 'SG Gold 6':
                      event.value = 3500;
                      break;

                      case 'SG Gold 10':
                      case 'SG Gold 13':
                      case 'SG Gold 16':
                      event.value = '$4000';
                      break;

                      case 'SG Silver 4':
                      case 'SG Silver 11':
                      case 'SG Gold 7':
                      case 'SG Gold 11':
                      case 'SG Gold 14':
                      event.value = '$5000';
                      break;

                      case 'SG Gold 12':
                      event.value = 5250;
                      break;

                      case 'SG Silver 6':
                      case 'SG Gold 3 w/HRA':
                      case 'SG Gold 8 w/HRA':
                      case 'SG Gold 15':
                      event.value = $6000;
                      break;

                      case 'SG Silver 8':
                      event.value = '$6250';
                      break;

                      case 'SG Bronze 1':
                      case 'SG Bronze 2':
                      case 'SG Bronze 3':
                      case 'SG Silver 1':
                      case 'SG Silver 2':
                      case 'SG Silver 3':
                      case 'SG Silver 7':
                      case 'SG Silver 9':
                      case 'SG Silver 10':
                      case 'SG Gold 4':
                      case 'SG Silver 7':
                      case 'SG Silver 9':
                      case 'SG Silver 10':
                      case 'SG Gold 4':
                      case 'SG Gold 5 w/HRA':
                      event.value = 6350;
                      break;

                      default:
                      event.value = '';
                      break;
                      }

                       

                      var a = this.getField("SUPPDENPLANID").value;
                      var b = this.getField("MEDOOP").value;
                      switch(true){
                      default:
                      event.value = "";
                      break;

                      case (a == 'DEHGNY02' && b == 1800):
                      event.value = 'DEHGPA01';
                      break;

                      case (a == 'DEHGNY02' && b == 2000):
                      event.value = 'DEHGPB01';
                      break;
                      ...
                      }

                       

                      For long scripts it is best to provide a link to the form.

                      • 8. Re: using value from one form field in another form field
                        Branchard0902 Level 1

                        I didn't know about a switch statement but I like it!

                        But I'm still not getting the result I need in the SUPPORTHOPLANID field.

                        I honestly don't know how to post the entire form or anything on here.

                        And I've tried my script in the validate field and the custom calculation field.

                        Neither one produce the result I need but as soon as I go into edit the script and then just close the editor, it's there. But when I come all the way out of edit mode and just try to get that result, it doesn't populate.

                        • 9. Re: using value from one form field in another form field
                          try67 MVP & Adobe Community Professional

                          It needs to be a calculation script.

                           

                          You can post the file to a file-sharing website (like acrobat.com, or dropbox), and then post the link here.

                          • 11. Re: using value from one form field in another form field
                            try67 MVP & Adobe Community Professional

                            I think I know what's the issue... You didn't set the drop-down fields to

                            commit their selected values immediately (under Properties - Options). As a

                            result, the calculations only take place when you exit the field (ie click

                            outside of it, or tab to another field), and not when you're making a

                            selection.

                            • 12. Re: using value from one form field in another form field
                              Branchard0902 Level 1

                              YOU ARE BRILLIANT!!!!!

                               

                              I can't thank you enough for your help. I really have learned a lot from this little problem solving session!!!