4 Replies Latest reply on Aug 1, 2016 9:33 AM by gkaiseril

    getting a checkbox to autofill form


      Hi Everyone,


      So I have written some code for a checkbox when checked to auto fill in dropdowns and text fields with N/A. However I would like to know how to condense the code. An example of my code is below. I would really appreciate some help on finding a way to condense the code so it is not so long. I have a few check boxes that have over 900 lines to them.


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

      this.getField("tfusystemvalues1").readonly = false;

      this.getField("tfusystemvalues1").value = " ";

      this.getField("tfusystemvalues2").readonly = false;

      this.getField("tfusystemvalues2").value = " ";

      this.getField("tfusystemvalues3").readonly = false;

      this.getField("tfusystemvalues3").value = " ";

      this.getField("tfusystemvalues4").readonly = false;

      this.getField("tfusystemvalues4").value = " ";

      this.getField("tfusystemvalues5").readonly = false;

      this.getField("tfusystemvalues5").value = " ";

      this.getField("tfusystemvalues6").readonly = false;

      this.getField("tfusystemvalues6").value = " ";

      this.getField("tfusystemvalues7").readonly = false;

      this.getField("tfusystemvalues7").value = " ";

      this.getField("softwarekit").readonly = false;

      this.getField("softwarekit").value = " ";

          } else { 

      this.getField("tfusystemvalues1").readonly = true;

      this.getField("tfusystemvalues1").value = "X";

      this.getField("tfusystemvalues2").readonly = true;

      this.getField("tfusystemvalues2").value = "X";

      this.getField("tfusystemvalues3").readonly = true;

      this.getField("tfusystemvalues3").value = "X"

      this.getField("tfusystemvalues4").readonly = true;

      this.getField("tfusystemvalues4").value = "X"

      this.getField("tfusystemvalues5").readonly = true;

      this.getField("tfusystemvalues5").value = "X"

      this.getField("tfusystemvalues6").readonly = true;

      this.getField("tfusystemvalues6").value = "X"

      this.getField("tfusystemvalues7").readonly = true;

      this.getField("tfusystemvalues7").value = "X"

      this.getField("softwarekit").readonly = true;

      this.getField("softwarekit").value = "X";


        • 1. Re: getting a checkbox to autofill form
          try67 MVP & Adobe Community Professional

          You can condense this code by a lot by placing the field names in an array and then using a loop to iterate over them, like this:


          var fields = ["tfusystemvalues1", "tfusystemvalues2", "tfusystemvalues3", "tfusystemvalues4", "tfusystemvalues5", "tfusystemvalues6", "tfusystemvalues7", "softwarekit"];
          for (var i in fields) {
              var f = this.getField(fields[i]);
              if (event.target.value=="Off") {
                  f.readonly = false;
                  f.value = " ";
              } else {
                  f.readonly = true;
                  f.value = "X";
          • 2. Re: getting a checkbox to autofill form
            austinc86391025 Level 1

            Thank you very much for this info. I do have a question though. Is there a way to make the var fields be like this for example: tfusystemvalues1 - 7

            That way I do not have to type out each one?? And if I can do that will it error out when looking for the next number in the field?

            • 3. Re: getting a checkbox to autofill form
              try67 MVP & Adobe Community Professional

              Yes, that is possible, using another loop. You can do it like this:


              var fields = [];
              for (var i=1; i<=7; i++) {
              • 4. Re: getting a checkbox to autofill form
                gkaiseril MVP & Adobe Community Professional

                Not with your field names. I would look at using hierarchical field names. If your field name has a parent name of : tfusystemvalues, you will have 7 children fields named : tfusystemvalues.0 thru : tfusystemvalues.6. You can then us a loop with a control whose value ranges from 0 to 6 and loop through or you can use the getArray() method on the parent field object and have all the children's field object in an array and then you can process each element in the array using the length of the array for controlling the loop.