10 Replies Latest reply on Jan 19, 2014 12:26 AM by anakdagang

    Conditional Formula between Check Box, Combo Box and Text Field

    anakdagang

      I am very new in this area and just trying to figure out things here. Anyway, what I am trying to do is quite straight forward. I have a TextField, which the content is depending on what being selected in the CheckBox and ComboBox. The TextField shall give the value of the membership fee depending either he is Local or Abroad (CheckBox) and depending on Age Categories (ComboBox). Could you please help me in getting the script? Really appreciate it and thanks a lot in advance.

        • 1. Re: Conditional Formula between Check Box, Combo Box and Text Field
          try67 MVP & Adobe Community Professional

          Basically it would be something like this (I'm just inventing values and field names here, since you didn't specify anything):

           

          event.value = "";

          var type = this.getField("Type").value;

          var age = this.getField("Age").value;

           

          if (type=="Local") {

              if (age=="0 to 10")

                  event.value = 10;

              else if (age=="11 to 20")

                  event.value = 20;

              else if (age=="21 to 50")

                  event.value = 30;

              else if (age=="50 or higher")

                  event.value = 50;

          } else if (type=="Abroad") {

              if (age=="0 to 10")

                  event.value = 20;

              else if (age=="11 to 20")

                  event.value = 40;

              else if (age=="21 to 50")

                  event.value = 60;

              else if (age=="50 or higher")

                  event.value = 100;

          }

           

          This script should be the custom calculation script of the fee text field.

          • 2. Re: Conditional Formula between Check Box, Combo Box and Text Field
            gkaiseril MVP & Adobe Community Professional

            The "switch" statement is another choice:

             

            ar type = this.getField("Type").value;
            var age = this.getField("Age").value;

            switch(true) {
            // local
            case (type == "Local" && age == "0 to 10"):
            event.value = 10;
            break;
            case (type == "Local" && age == "11 to 20"):
            event.value = 20;
            break;
            case (type == "Local" && age == "21 to 50"):
            event.value = 30;
            break;
            case (type == "Local" && age == "50 or higher"):
            event.value = 50;
            break;
            // abroad
            case (type == "Abroad" && age == "0 to 10"):
            event.value = 20;
            break;
            case (type == "Abroad" && age == "11 to 20"):
            event.value = 40;
            break;
            case (type == "Abroad" && age == "21 to 50"):
            event.value = 60;
            break;
            case (type == "Abroad" && age == "50 or higher"):
            event.value = 100;
            break;
            default:
            event.value = "";
            break;
            } // end switch;

            • 3. Re: Conditional Formula between Check Box, Combo Box and Text Field
              anakdagang Level 1

              hi gilad,

              thanks for the help!! i was trying to figure it out how earlier and somehow managed to get it work as the followings:

              i have 3 fields, 1 Check Box ("Yes" or "No"), 1 Combo Box (1 = < 3 Years Old; 2 = 2-12 Years Old, 3 = >13 Years Old) and 1 Text Box.  i named the fields as CheckKid, ComKid and FeeKid. FeeKid is the Text Field where the content depending on the slection made on the CheckKid AND the ComKid.

               

              after playing around with it,  i defined a script in the CheckKid.. Actions.. Mouse Up with the following:

               

              //checkbox condition for kids fee

              if(event.target.value == "Yes" && this.getField("ComKid1").value == 1)

              {this.getField("FeeKid1").value = "0.000";}

              else

              if(event.target.value == "Yes" && this.getField("ComKid1").value == 2)

              {this.getField("FeeKid1").value = "1.000";}

              else

              if(event.target.value == "Yes" && this.getField("ComKid1").value == 3)

              {this.getField("FeeKid1").value = "3.000";}

              else

              {this.getField("FeeKid1").value = "";}

               

              somehow it worked but i have to make the selection on the Combo Field FIRST and then on the Check Box in order to get the correct value in the Text Field. is there a better way to write the script like in the Text Field itself rather than in the Check Field?

               

              thanks again

              • 4. Re: Conditional Formula between Check Box, Combo Box and Text Field
                anakdagang Level 1

                thanks gkaiseril.. i will try this one out. my other problem is, i am building and creating the fillable form in Acrobat Pro 8. evrything seems working including the automatic calculation as defined. send the form to my personal email and i tried it out by opening it from my iPhone (or iPad) thru Adobe Reader. all the fields are editable BUT the field (with defined conditional value) DOES NOT convert the value AUTOMATICALLY. any idea why?

                • 5. Re: Conditional Formula between Check Box, Combo Box and Text Field
                  gkaiseril MVP & Adobe Community Professional

                  Mobile devices are not as powerful or fully equipped as a desktop or laptop computer. Specifically they are missing JavaScript. A lot will depend upon what application is used on the mobile device. For the apple products PDF Expert appears to be the best product but there is still a lot of features and JavaScript that will not work with that app.

                  • 6. Re: Conditional Formula between Check Box, Combo Box and Text Field
                    anakdagang Level 1

                    thanks again gkaiseril.. you have been veery helpful!!! really appreciate it

                    • 7. Re: Conditional Formula between Check Box, Combo Box and Text Field
                      George_Johnson MVP & Adobe Community Professional

                      Your script won't work with Adobe Reader on iOS, but the other two should. JavaScript isn't missing from Reader for iOS, but it is fairly limited, so you have to work with what's available, and event.target isn't for the Mouse Up event of check boxes.

                      • 8. Re: Conditional Formula between Check Box, Combo Box and Text Field
                        try67 MVP & Adobe Community Professional

                        Why aren't you using the code I gave you? It's meant to be the custom calculation code of the text field, so it doesn't matter which field you edit, the field will always update.

                        • 9. Re: Conditional Formula between Check Box, Combo Box and Text Field
                          anakdagang Level 1

                          hi gilad,

                          tried your code already and and changed accordingly to mine:

                          1. event.value = "";

                          var type = this.getField("NatKid1").value;

                          var age = this.getField("AgeKid1").value;

                           

                          if (type=="Yes") {

                              if (age=="1")

                          event.value = 0;

                              else if (age=="2")

                          event.value = 1;

                              else if (age=="3")

                          event.value = 3;

                          } else if (type=="No") {

                              if (age=="1")

                          event.value = 0;

                              else if (age=="2")

                          event.value = 1.5;

                              else if (age=="3")

                          event.value = 4;

                          }

                           

                          and it works!!! still doing some trial run on some devices/gadgets and shall let you know. thanks again, gilad

                          • 10. Re: Conditional Formula between Check Box, Combo Box and Text Field
                            anakdagang Level 1

                            hi gkaiseril.. your code works too!! thanks..

                             

                            my other set back now is that, i have another Text Field, showing the sum of ALL the fees. the fees now change automatically (using gilad's or gkaiserl's code) BUT the sum of ALL these fees does not calculate the value immediately. need to tab my cursor to few fields ahead before getting the sum value updated to the right sum.