3 Replies Latest reply on May 5, 2015 2:42 PM by gkaiseril

    using a check box to copy a text field

    timo36974274

      i'm trying to have it so that

      address 1

      will equal address 2

      if you click the check box same

       

      the code i tried

       

      this.getField("Mailing address") = this.getField("address");

      seems simple enough but doesn't do anything.

       

      also tried this

       

        if(same.checked == true) {

          mailing.value = address.value;

         

        }

        • 1. Re: using a check box to copy a text field
          gkaiseril MVP & Adobe Community Professional


          Have you checked the JavaScript console for any errors?

           

          Use the combination of the [Ctrl} + "J" keys to open the JavaScript console.

           

          Field names need to be spelled and capitalize just like the field's name.

           

          You might want to add some additional code to view what is happening,

           

          You could create a button and use the following code for the mouse up action:

          function GetField(cName) {

            var oField = this.getField(cName);

            if(oField ==  null) app.alert("Error accessing field " + cName, 1,0);

            return oField;

            } // end GetField fucntion;

           

            console.show();

            console.clear();

            var oMailing = GetField("Mailing address");

            console.println("Mailing address value: " + oMailing.valueAsString);

            var oAddress = GetField("address");

            console.println("address value: " + oAddress.valueAsString);

            var oSame = GetField("same");

            console.println("same value: " + oSame.value);

          • 2. Re: using a check box to copy a text field
            timo36974274 Level 1

            i typed that in and it gave me no error it returned

            address = sample

            mailing   nothing

            and same = Yes

             

            currently I'm using

            if (("same").checked == Yes)

            {

            getField("mailing").value = getField("address").valueAsString; 

            }

            which does not work

            however

            getField("mailing").value = getField("address").valueAsString; 

            works but doesn't check if the box is checked or not so it seems the check box is the problem but based on your code it is returning Yes

            I also tried

            if (("same").checked == true)  which also did not work. so it seems i'm missing something for this line.


            • 3. Re: using a check box to copy a text field
              gkaiseril MVP & Adobe Community Professional

              So the script I provided gives you the expected results.

               

              Can you see the difference in the provided code and your code?

               

              Before I can get the value of any field, I need to establish an object variable for the field in question. I can then access the field's value.

               

              So to see the value of the field named "same" I need to obtain the object for that field using code like:

               

              var oSame = this.getField("same");

               

              Now to see the value property of the field one needs to get the value from the object and to compare it to a string value one needs to put the string value between quotation marks to differentiate the character string from a variable name.

               

              if(oSame.value == "Yes") app.alert("Match");

               

              Have you looked at any reference or tutorials about JavaSdript?