9 Replies Latest reply on Jun 6, 2012 7:13 AM by CarrionMisery

    Multiple Check Boxes Update Text Box

    CarrionMisery Level 1

      I have 7 check boxes next to 7 text boxes. The text boxes read:

      1. Red
      2. Blue
      3. Green
      4. Cyan
      5. Magenta
      6. Yellow
      7. Black

       

      I have an 8th text box that is supposed to display the check boxes that are selected. So if 1, 3, 5 and 7 are checked, the 8th box should say:

       

      Red Green Magenta Black

       

      I already found a way to make this work, but the length of code is insane. I have to make an if, then statement for every single possible combination:

       

      else if((redcheck == "Yes") && (bluecheck != "Yes") && (greencheck == "Yes") && (cyancheck != "Yes") && (magentacheck == "Yes") && (yellowcheck != "Yes") && (blackcheck == "Yes"))

                  event.value = this.getField("red").value + this.getField("green").value + this.getField("magenta").value + this.getField("black").value;

       

      This is brain numbing and I keep losing my place of what else needs to be combined. I have a feeling there is a more simple way to accomplish this. Any help will be appreciated.

        • 1. Re: Multiple Check Boxes Update Text Box
          gkaiseril MVP & Adobe Community Professional

          I would set the export value of each check box to the color for that check box. Then for the script, I would load the value of each check box that does not have a value of "Off" into an array. And then I can can set the field value equal to the contents of the "joined" array.

           

          // array of field name to process

          var aFieldNames = new Array("CBColor.0", "CBColor.1", "CBColor.2", "CBColor.3", "CBColor.4", "CBColor.5", "CBColor.6");

          // variable for value of an individual field

          var cColor = "";

          // array of values from fields with a value not equal to "Off"

          var aColors = new Array();

          // process each field in field name array

          for (i = 0; i < aFieldNames.length; i++) {

          // get the value from a field

          cColor = this.getField(aFieldNames[i]).value;

          // add value to array of colors only if value not equal to "Off"

          if(cColor != "Off") {

          aColors[aColors.length] = cColor;

          } // end field value not "Off"

          } // end loop field name processing

          // set value to the values in the color array

          event.value = aColors.join(", ");

           

          Change the array of field names as needed.

          • 2. Re: Multiple Check Boxes Update Text Box
            CarrionMisery Level 1

            This looks promising, but I'm a little confused on which fields I'm supposed to change. I mean, I understand where I switch the checkboxes, but what is "aColor" and "cColor", and where do I declare the names of all 7 text boxes?

             

            Also I see a potential problem. I need the text fields to be editable so setting the export value isn't going to work. For example, if I want to the user to switch "red" to "purple" so the 8th text box can update to :

             

            Purple Green Magenta Black

            • 3. Re: Multiple Check Boxes Update Text Box
              gkaiseril MVP & Adobe Community Professional

              The field name are in the array aFieldNames. If you want to change the values, then change the export value of the check box. There are comments within the script to help explain what is being done.

               

              You could add a script to each text field to change the "exportValues" of the associated check box based on the value of the text field so as a text field is changed, the check box' export value gets changed.

               

              You should also allow for the clearing of the from and not losing your options data data.

              • 4. Re: Multiple Check Boxes Update Text Box
                gkaiseril MVP & Adobe Community Professional

                OK.

                 

                Try this script and change the field names as necessary:

                 

                // define array of pairs of check box and associated text fields

                // each primary element of the array consist of the check box field and the text field for that check box

                // field names are an array of 2 items the first item the check box field name and the second the text field name

                var aFields = new Array(

                ["CBOption.0", "OptionText.0"],

                ["CBOption.1", "OptionText.1"],

                ["CBOption.2", "OptionText.2"],

                ["CBOption.3", "OptionText.3"],

                ["CBOption.4", "OptionText.4"],

                ["CBOption.5", "OptionText.5"],

                ["CBOption.6", "OptionText.6"]

                );

                console.show();

                console.clear();

                console.println("Number of fields: " + aFields.length);

                // define array for values of text for selected fields

                var aValues = new Array();

                // process the fields in the aFields array

                for ( i = 0; i < aFields.length; i++) {

                console.println("Check box: " + aFields[i][0] + " Text field:" + aFields[i][1]);

                console.println("Check box value: " + this.getField(aFields[i][0]).value);

                // see if check box field i is not off

                if(this.getField(aFields[i][0]).value != "Off") {

                console.println("Text field value: " + this.getField(aFields[i][1]).value);

                // check box is selected - add value of associated text field

                aValues[aValues.length] = this.getField(aFields[i][1]).value;

                } // end check box not off

                } // end loop for aField element

                // set field value to contents of aValues array

                event.value = aValues.join("; ");

                 

                It will even show you the field names and values as it runs.

                • 5. Re: Multiple Check Boxes Update Text Box
                  CarrionMisery Level 1

                  Amazing! This last one was it. Thanks for the help. However, every time I check a box, the debugger box pops up. I've never seen this before. Any idea?

                  • 6. Re: Multiple Check Boxes Update Text Box
                    CarrionMisery Level 1

                    Obviously, I'm not a very good reader. I see the console code you put in there. Thanks a ton!

                    • 7. Re: Multiple Check Boxes Update Text Box
                      CarrionMisery Level 1

                      Hello again,

                       

                      I was going to start a new thread, but I thought I'd ask here since my question still relates.

                       

                      Instead of the text boxes having words (cyan, etc) what if they are currency formatted?

                       

                      I tried to use the successful code you gave me before, but the currency format of course doesn't transfer over. I have searched all over, but no luck. What do I need to do for each line to have a $0,000.00 format after it is transfered?

                       

                      Thanks again.

                      • 8. Re: Multiple Check Boxes Update Text Box
                        gkaiseril MVP & Adobe Community Professional

                        You need to set each Field where you placing the value tot he correct format. The format with currency is a visible only property, the raw number without the currency symbol is used in calculations. and it is assumed the creator is keeping the currency of the data consistent.

                         

                        Sort of like computing rocket paths with miles and kilometers, one needs to keep track of the unit of measurement and not mix them in the same calculation.

                        • 9. Re: Multiple Check Boxes Update Text Box
                          CarrionMisery Level 1

                          Yeah, I understand that well. Same as the code you gave me before, but the difference is OptionText.0 though 6 are calculated fields, and when I check a box, they are fed into a new multi-line text box. The problem is when they're fed in, it drops the currency format, and the decimal in the new multi-lie text box. So I found the script that forces a currency format (pages 8 - 10) which works on its own:

                           

                          http://www.acrotex.net/blog/wp-content/uploads/2011/07/pdfblog_22.pdf

                           

                          I need the code to apply the format for each of the OptionText fed into the multi-line textbox.

                           

                          var aFields = new Array(

                          ["CBOption.0", "OptionText.0"],

                          ["CBOption.1", "OptionText.1"],

                          ["CBOption.2", "OptionText.2"],

                          ["CBOption.3", "OptionText.3"],

                          ["CBOption.4", "OptionText.4"],

                          ["CBOption.5", "OptionText.5"],

                          ["CBOption.6", "OptionText.6"]

                          );

                           

                           

                          I feel it's possible to make the script say, "apply this format for every OptionText fed into the new multi-line text." The problem is I don't know where I'm supposed to implement this currency format code into the script you gave me here:

                           

                          // define array of pairs of check box and associated text fields

                          // each primary element of the array consist of the check box field and the text field for that check box

                          // field names are an array of 2 items the first item the check box field name and the second the text field name

                          var aFields = new Array(

                          ["CBOption.0", "OptionText.0"],

                          ["CBOption.1", "OptionText.1"],

                          ["CBOption.2", "OptionText.2"],

                          ["CBOption.3", "OptionText.3"],

                          ["CBOption.4", "OptionText.4"],

                          ["CBOption.5", "OptionText.5"],

                          ["CBOption.6", "OptionText.6"]

                          );

                          console.show();

                          console.clear();

                          console.println("Number of fields: " + aFields.length);

                          // define array for values of text for selected fields

                          var aValues = new Array();

                          // process the fields in the aFields array

                          for ( i = 0; i < aFields.length; i++) {

                          console.println("Check box: " + aFields[i][0] + " Text field:" + aFields[i][1]);

                          console.println("Check box value: " + this.getField(aFields[i][0]).value);

                          // see if check box field i is not off

                          if(this.getField(aFields[i][0]).value != "Off") {

                          console.println("Text field value: " + this.getField(aFields[i][1]).value);

                          // check box is selected - add value of associated text field

                          aValues[aValues.length] = this.getField(aFields[i][1]).value;

                          } // end check box not off

                          } // end loop for aField element

                          // set field value to contents of aValues array

                          event.value = aValues.join("; ");

                           

                           

                          It'd be great if you have the solution. You've been so helpful. Thank you.