2 Replies Latest reply on Nov 27, 2013 8:39 AM by marrones1234

    Problems with selecting multiple checkboxes

    marrones1234

      Hi! I'm very new to Javascript and am trying to navigate my way through adding some to a PDF document. 

       

      I have a document with groups of checkboxes, like

       

      • Fiber
        • Total Dietary Fiber
        • Soluble Dietary Fiber
        • Insoluble Dietary Fiber
        • Pectins

       

      So if Fiber is selected, I would like all four options below it to also be automatically selected, and deselected if Fiber is unchecked. 

       

      I was trying to alter code from this discussion, http://forums.adobe.com/message/3496310, but I can't get it to work correctly. 

       

      This is what I have now -

       

      function cbControl() {

       

          var f1 = this.getField("Fiber");

          var f2 = this.getField("F1");

          var f3 = this.getField("F2");

          var f4 = this.getField("F3");

          var f5 = this.getField("F4");

       

      if (event.target === f1) {

              f2.value = "On";

                     f3.value = "On";

              f4.value = "On";

              f5.value = "On";

             }

      }

       

      Any help would be greatly appreciated!

        • 1. Re: Problems with selecting multiple checkboxes
          gkaiseril MVP & Adobe Community Professional

          What specifically  is not working properly?

           

          Are you calling this function? I do not see the code.

          When are you calling this function?

           

          The value of a check box or radio button group is either "Off" (no item selected), or the export or checked value for the specific field. The default value of a button is :Yes".

           

          For the mouse up action:

          function cbControl() {

              var f2 = this.getField("F1");

              var f3 = this.getField("F2");

              var f4 = this.getField("F3");

              var f5 = this.getField("F4");

          if (event.target.value == "Yes") {

                  f2.value = "Yes";

                  f3.value = "Yes";

                  f4.value = "Yes";

                  f5.value = "Yes";

                 } else {

               f2.value = "Off";

                  f3.value = "Off";

                  f4.value = "Off";

                  f5.value = "Off";

                 }

          }

           

          cbControl();

           

           

          Check the export.option values for you check boxes and adjust your code accordingly.

           

          Another option would be to use the "isBoxChecked" methiod to test if the item is selected and use the "chekcThisBox" to check or un-check the other boxes.

           

          function cbControl() {
              var f2 = this.getField("F1");
              var f3 = this.getField("F2");
              var f4 = this.getField("F3");
              var f5 = this.getField("F4");
          var bSelected = event.target.isBoxChecked(0);
              f2.checkThisBox(0,bSelected);
              f3.checkThisBox(0,bSelected);
              f4.checkThisBox(0,bSelected);
              f5.checkThisBox(0,bSelected);
          }

          cbControl();

          • 2. Re: Problems with selecting multiple checkboxes
            marrones1234 Level 1

            Thank you so much for the response!!  I figured out that I had things in the wrong spots. 

             

            I moved the first chunk of code you provided into the mouseup action of the Fiber checkbox, and it's working!

             

            Do you know, if say Fiber is checked and then the user unchecks one of the options below, is there a way for Fiber to then be unchecked? 

             

            Thank you again!