3 Replies Latest reply on Mar 18, 2015 2:23 AM by try67

    Checkboxes populate text fields

    bryann55120965

      In the BUYER section of the form below I have two check boxes that represent addresses (TTL & Ancon).  When checked, I want the address fields in that section to auto populate.  Can you help me out with the JavaScript code to make this happen?  thanks

       

      Shipping Request Form_Rev.1.jpg

        • 1. Re: Checkboxes populate text fields
          gkaiseril MVP & Adobe Community Professional

          You will need to use custom JavaScript for that and that will mean you need to provide a lot more information like all field names that will be used in the script, fixed text data that would be used in the script and some logic as to how it should work.

          • 2. Re: Checkboxes populate text fields
            bryann55120965 Level 1

            Thanks for the quick response.  To try to keep this simple, if the TTL box is checked, then all the address fields below are populated with it's address.  If the Ancon box is checked that a different address is populated.  If someone writes the Javascript code and can simply copy the format and change the field names.

             

            -Bryan

            • 3. Re: Checkboxes populate text fields
              try67 MVP & Adobe Community Professional

              You can use this code as the MouseUp action for the TTL box. It copies the values of the "source" fields to the "target" fields when the box is ticked (and sets then as read-only), and clears them when the box is un-ticked (and sets them as editable once more):

               

              var sourceFields = ["Address 1", "City 1", "Zip 1"];
              var targetFields = ["Address 2", "City 2", "Zip 2"];
              
              for (var i in targetFields) {
                  var f = this.getField(targetFields[i]);
                  if (event.target.value=="Off") {
                      f.value = "";
                      f.readonly = false;
                  } else {
                      f.value = this.getField(sourceFields[i]).valueAsString;
                      f.readonly = true;
                  }
              }