4 Replies Latest reply on Jun 2, 2012 1:26 PM by Smitch1581

    Checkbox values

    Smitch1581 Level 1

      Hi

       

      I have this script that when a check box is ticked it inserts the values in to a new field. It removes the "Off" value and all works well

      At the moment when 2 check boxes are ticked it enters both values into the field. What i would reallly like is that when any 2 check boxes are ticked, i would like the text field to display MUL. Can any body help me finish of my code, its beaten me ;(

       

      // array of field names to use

      var aFieldNames = new Array("HOR", "LIV", "CAR", "FUR", "HEA", "MIN", "HOU", "Skills", "ICT", "BDS", "None");

      // clear the result field

      event.value = "";

      // variable for testing the value of a single field

      var cItem = "";

      // array of values not equal to "Off"

      var aValues = new Array();

      // process each field name

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

      // get i name's field value as a string

      cItem = this.getField(aFieldNames[i]).valueAsString;

      // see if value not equal to "Off"

      if(cItem != "Off") {

      // add to array of non "Off" values

      aValues[aValues.length] = cItem;

      } // end not "Off" value

      } // end loop names

      // set field value

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

       

      var sect = this.getField("R1").length;

      if (sect == "String")

      {

      event.value = "MUL";

      }

       

       

       

      Thanx in advance

        • 1. Re: Checkbox values
          gkaiseril MVP & Adobe Community Professional

          You could just count how many check boxes have a value other than "Off" and then fill in the field base on that value. Zero and one is blank 2 or greater is "Mul".

          • 2. Re: Checkbox values
            Smitch1581 Level 1

            Thanx for the reply. For some reason i just cant get this. How do i i check the value is other than "Off"?

            • 3. Re: Checkbox values
              gkaiseril MVP & Adobe Community Professional

              You are already adding the value to an array when the check box value is not "Off" or the check box has a value other than off.

               

              You need to define a variable to hold the count and then of adding the value of the check box to the array, you increment the count.

               

              Another idea, since you have the non-Off values in an array just check the length or number of items in the array. If the length is greater than 1 then there are multiple entries. If the value is zero then there are no check boxes checked.

               

              change:

               

              // set field value

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

               

              var sect = this.getField("R1").length;

              if (sect == "String")

              event.value = "MUL";

              }

               

              To

               

              // set the field value

              event.value ="";

              if(aValues.length > 1)

              event.value = "Mul";

              • 4. Re: Checkbox values
                Smitch1581 Level 1

                Thank you very much! Thats was driving me up the wall. Knew what i wanted to do but just couldnt do it!

                 

                Thanx again