1 Reply Latest reply on Apr 30, 2009 1:42 PM by gkaiseril

    How to set field checkbox values based on another field

    rmorrey Level 1

      I'm trying to provide the user with the ability to check one box "Check All" which would then set the check boxes for a section to the same value as shown in the example.  Anyone know how I can accomplish this?

      Thank you.

       

      Example

       

      General Category A     [  ] Check All

           [  ]  Item 1

           [  ]  Item 2

           [  ]  Item 3

           [  ]  Item 4

       

      If user selects "Check All", all the Items in the list for "General Category A" are then checked automatically.

        • 1. Re: How to set field checkbox values based on another field
          gkaiseril MVP & Adobe Community Professional

          You can create a document level function to check a series of check fiels as long as they all have the same checked value.

           

          // document level function that can be used for many sections
          function CheckAll(aFields, sChecked) {
          // test to see Check All box for being checked
          // and if checked set to aFields to checked value
          // otherwise clear fields
          if(this.getField(event.target.name).value == 'Off') {
          // field unchecked
          this.resetForm(aFields); // clear the fields
          // end box not checked
          } else {
          // check all box has been checked
          // loop through the fields to check
          for (i = 0; i < aFields.length; i++) {
          // all fields are assumed to have a value of 'Yes' when selected
          var f = this.getField(aFields[i]); // get field for element i
          f.value = sChecked; // set to checked value
          } // end loop to check
          // end checked
          } // end unchecked
          } // end CheckAll function
          // end document level function

           

          You can then add a mouse up aciton for the check all check box:


          // mouse up action for check all check box
          // define array of check box fields to process
          var aSecFields = new Array('Item 1', 'Item 2', 'Item 3', 'Item 4');
          // call CheckAll function
          // passing the array list of field names and checked value
          CheckAll(aSecFields, 'Yes');

           

          or you can use 1 line of executable code:

           

          // mouse up action for check all check box
          // call CheckAll function
          // passing the array list of field names and checked value
          CheckAll(['Item 1', 'Item 2', 'Item 3', 'Item 4'], 'Yes');