2 Replies Latest reply on May 3, 2015 9:59 AM by bpwhistler

    How do I make a checkbox autopopulate a text field

    bpwhistler Level 1

      I have 2 text fields named MailingAddress and GarageAddress.

       

      I would like to have a checkbox next to my MailingAddress field that when checked would autopopulate my GarageAddress with the value from MailingAddress.

       

      I scrounged around the forums and cobbled this together (with my very limited JavaScript knowledge)...but keep getting a syntax error.  I'm sure it's something obvious...if you understand JavaScript!

       

      Any help would be greatly appreciated

       

      var aMailing = this.getField("MailingAddress");
      var aGarage = this.getField("GarageAddress");

      if(this.getField(event.target.name).value == "Yes")
      {
      // copy Mailing address to Garage address;
      aMailing.value = aGarage.value;
      }
      aGarage.readonly = true; // make GarageAddress readonly;
      }

      else

      {
      aGarage.readonly = false; // clear readonly
      this.resetForm([aGarage.name]) // reset GarageAddress
      }

        • 1. Re: How do I make a checkbox autopopulate a text field
          try67 MVP & Adobe Community Professional

          You have syntax errors in your code... Also, it seems the logic of your code is reversed. You're copying the value from GarageAddress to MailingAddress, instead of what you described. I would suggest using this code (as the MouseUp event of the check-box) instead:

           

          var aMailing = this.getField("MailingAddress");
          var aGarage = this.getField("GarageAddress");
          
          if (event.target.value == "Yes") {
              // copy Mailing address to Garage address;
              aGarage.value = aMailing.valueAsString;
              aGarage.readonly = true; // make GarageAddress readonly;
          } else {
              aGarage.readonly = false; // clear readonly
              this.resetForm([aGarage.name]) // reset GarageAddress
          }
          
          • 2. Re: How do I make a checkbox autopopulate a text field
            bpwhistler Level 1

            Thank you...that worked perfectly.