1 Reply Latest reply on Dec 2, 2016 1:42 AM by try67

    Need dropdown fields to populate checkbox (Yes, No)

    lisak51453826

      My customer has a form with a Checkbox field called "WeekendCare" With options "Yes" and "No" 

       

      I have 8 dropdown fields (Weekend open and close times) that will need to be examined to determine whether to populate the yes/no. If ANY of the following 8 dropdown fields have a value of a time in the dropdown (other than the default "Select") - the Weekend Care gets checked "Yes"  - if none have values, then "No" is checked.

       

      The dropdown fields are named:

       

      CenterOpenSaturday

      CenterOpenSaturday2

      CenterCloseSaturday

      CenterCloseSaturday2

      CenterOpenSunday

      CenterOpenSunday2

      CenterCloseSunday

      CenterCloseSunday2

       

      Can you help with a javascript for this?

      And please let me know which field to place the javascript in... that is confusing sometimes.

      Thanks for your help!

        • 1. Re: Need dropdown fields to populate checkbox (Yes, No)
          try67 MVP & Adobe Community Professional

          Yes, this kind of operation can be quite tricky. I think the best was of doing it is to create a hidden text field and use its calculation event for this task, even if the field itself has nothing to do with it. You can use this code to achieve it:

           

          var dropdowns = [
              "CenterOpenSaturday", "CenterOpenSaturday2", "CenterCloseSaturday", "CenterCloseSaturday2", "CenterOpenSunday", "CenterOpenSunday2", "CenterCloseSunday", "CenterCloseSunday2"
          ];
          
          var tickBox = false;
          for (var i in dropdowns) {
              var f = this.getField(dropdowns[i]);
              if (f.valueAsString!=f.defaultValue) {
                  tickBox = true; break;
              }
          }
          this.getField("WeekendCare").checkThisBox(0, tickBox);