5 Replies Latest reply on Dec 26, 2013 7:44 AM by gkaiseril

    Checking Boxes based on value in a Text Field

    MikeVTelco

      Hi.

       

      I'm building a pdf form in Acrobat X Professional. I want to add JavaScript to two checkboxs to achieve the following:

      if the value of a text field (LType) is equal to 61, 64, 66, or 67, the first checkbox (PlanACheck) will have the value of being checked.  If the value of the text field (LType) is equal to 60, 62 or 63, the second checkbox (PlanBCheck) will have the value of being checked.

       

      I have no experience in Javascript other than copying and pasting, so I'm not sure I'm using the right language to search. If anyone can provide any guidance, I would greatly appreciate it.

       

      Thanks a lot!

        • 1. Re: Checking Boxes based on value in a Text Field
          try67 MVP & Adobe Community Professional

          Usually this kind of thing will be implemented as the custom Calculation script of the target field, but check-boxes don't have a Calculation script, so we'll use the text field's Validation script to do it, with this code:

           

          this.getField("PlanACheck").checkThisBox(0, (event.value=="61" || event.value=="64" || event.value=="66" || event.value=="67"));

          this.getField("PlanBCheck").checkThisBox(0, (event.value=="60" || event.value=="62" || event.value=="63"));

          • 2. Re: Checking Boxes based on value in a Text Field
            MikeVTelco Level 1

            Hmm, it does work, but the value in the LType text field is being auto-populated from another area, and is actually going to be a hidden field that the user won't even know about.  When I try this, the number is pre-populated into the LType text field, but the check boxes aren't checked unless I go back and change the value in the LType field manually and then move to the next field to get the Validation to go off.  Is there a way to have it check the information in the text field without having to re-enter the information?

            • 3. Re: Checking Boxes based on value in a Text Field
              try67 MVP & Adobe Community Professional

              Then you'll need to incorporate this code in the code that calculates the value of the text field.

              1 person found this helpful
              • 4. Re: Checking Boxes based on value in a Text Field
                MikeVTelco Level 1

                That worked perfectly!  Thank you very much!

                • 5. Re: Checking Boxes based on value in a Text Field
                  gkaiseril MVP & Adobe Community Professional

                  If both check boxes are mutually exlcusive why not use just one check box in  a mutually exclusive group and assign a different export value to each individual check box. This as the value of the check boxe is set by script the other check box would un-check. If none of the resulting values selects plan a or b then you can un-check both check boxes with a value of "Off".

                  I would also consider using the "switch" statement because it maybe clearer than a nested if statement.

                  One could add the following script to which takes the nLtype value and either seelcts a plan check box or clears both boxes. One only needs to supply the value of "nLType" parameter.

                  function SelectPlan(nLType) {
                  switch(true) {
                  // Plan A selection values;
                  case (nLtype == 61):
                  case (nLtype == 66):
                  case (nLtype == 67):
                  this.getField("PlanACheck").checkThisBox();
                  break;
                  // Plan B selection values;
                  case (nLtype == 60):
                  case (nLtype == 62):
                  case (nLtype == 63):
                  this.getField("PlanBCheck").checkThisBox();
                  break;
                  // all other values
                  default:
                  this.getField("PlanACheck").value = "Off";
                  this.getField("PlanBCheck").value = "Off";
                  break;
                  }

                  SelectPlan(nLType);

                   

                  With a complex form sometimes a sample is helpful in formulating an answer.