7 Replies Latest reply on Jan 19, 2016 11:10 AM by Florida Healtcare System

    As concatenate text from multiple checkbox

    Florida Healtcare System

      selections: example:

      1-checkbox: The car is

      2-checkbox: my property

      3-checkbox: rented 

       

      The results could be:

      The car is my property

      The car is rented

       

      etc.

        • 1. Re: As concatenate text from multiple checkbox
          try67 MVP & Adobe Community Professional

          You can use this script as the custom calculation script of the first field:

          event.value = this.getField("1-checkbox").value + " " + this.getField("2-checkbox").value;

           

          And this code for the second field:

          event.value = this.getField("1-checkbox").value + " " + this.getField("3-checkbox").value;

          • 2. Re: As concatenate text from multiple checkbox
            Florida Healtcare System Level 1

            Thanks for the answer, but what I really need is.

            Whenever you mark a check box displays the contents and then check all the boxes that go jogging.

             

             

            say we have 20 checkboxes and select 9 or 16, it should show only the text of the check box activated.

            Thank you for your help

            • 3. Re: As concatenate text from multiple checkbox
              try67 MVP & Adobe Community Professional

              So where is this text coming from? Is there a matching text field for each check-box, or do you want to hard code into the script?

              • 4. Re: As concatenate text from multiple checkbox
                gkaiseril MVP & Adobe Community Professional

                That is a little different from what you first described. It is also more complex. You showed an example with 3 check boxes but your example only had 2 of 3 items at a time selected. It might happen that 3 items could be selected but it would not be physically logical.

                 

                You heed to setup your check boxes so the "Selected: value is the text you want to populate the text field.

                 

                You may also need some controls to make sure lead-in statement like "The car is " is selected before either of the check boxes in the group "Ownership" is selected.

                 

                I feel you have not clearly explained you requirements for the script.

                • 5. Re: As concatenate text from multiple checkbox
                  Florida Healtcare System Level 1

                  I need say is that whenever SELECTIONS check this box to display a text.

                   

                   

                  if the selection is several check boxes for the texts to be displayed consecutively in any order.

                   

                   

                  forgiving translation

                  • 6. Re: As concatenate text from multiple checkbox
                    gkaiseril MVP & Adobe Community Professional

                    I would create a document level funtion to concatenate upto 3 fields at time and not include and values that have a null string. It would also support the ability to insert an options seperator characater if supplied and and not use a null string as the seperator.

                    A possible script:

                    // Concatenate 3 strings with separators where needed
                    function fillin(s1, s2, s3, sep) {

                    /*
                    Purpose: concatenate up to 3 strings with an optional separator

                    inputs:
                    s1: required input string text or empty string
                    s2: required input string text or empty string
                    s3: required input string text or empty string
                    sep: optional separator sting

                    returns:
                    sResult concatenated string
                    */

                    // variable to determine how to concatenate the strings
                      var test = 0; // all strings null
                      var sResult; // re slut string to return
                     
                    // force any number string to a character string for input variables
                      s1 = s1.toString();
                      s2 = s2.toString();
                      s3 = s3.toString();
                      if(sep.toString() == undefined) sep = ''; // if sep is undefined force to null

                    /*
                    assign a binary value for each string present 
                    so the computed value of the strings will indicate which strings are present
                    when converted to a binary value
                    */
                      if (s1 != "") test += 1; // string 1 present add binary value: 001
                      if (s2 != "") test += 2; // string 2 present add binary value: 010
                      if (s3 != "") test += 4; // string 3 present add binary value: 100

                      /* return appropriate string combination based on
                      calculated test value as a binary value
                      */
                      switch (test.toString(2)) {

                      case "0": // no non-empty strings passed - binary 0
                         sResult = "";
                      break;
                     
                      case "1": // only string 1 present - binary 1
                         sResult = s1;  
                      break;
                     
                      case "10": // only string 2 present - binary 10
                         sResult = s2;  
                      break;
                     
                      case "11": // string 1 and 2 present - binary 10 + 1
                         sResult = s1 + sep + s2; 
                      break;

                      case "100": // only string 3 present - binary 100
                         sResult = s3;
                      break;
                     
                      case "101": // string 1 and 3 - binary 100 + 001
                         sResult = s1 + sep + s3; 
                      break;
                     
                      case "110": // string 2 and 3 - binary 100 + 010
                         sResult = s2 + sep + s3; 
                      break;
                     
                      case "111": // all 3 strings  - binary 100 + 010 + 001
                         sResult = s1 + sep + s2 + sep + s3; 
                      break;
                     
                      default: // any missed combinations
                         sResult = "";
                      break;
                    }

                    return sResult;
                    }

                    Note that binary values are used to determine which combination of the 3 possible strings for concatenation is used to provide the result.

                    A possible custom calculation script for the text field could be:

                    var aFields = new Array("Check Box1", "Check Box2", "Check Box3");
                    var aValues = new Array();
                    for(var i = 0; i < aFields.length; i++) {
                    aValues[i] = this.getField(aFields[i]).value;
                    if(aValues[i] == "Off") aValues[i] = "";
                    } // process next field;
                    // clear result;
                    event.value = "";
                    // create concatenated value from the value of the fields;
                    for(var i = 0; i < aValues.length; i++) {
                    event.value = fillin(event.value, aValues[i], "", " ");
                    }

                     

                     

                    So with your example, checking all three results in:'

                     

                    The car is my property is rented

                     

                    It makes no practical sense since owning and renting are mutually exclusive.