6 Replies Latest reply on Nov 20, 2009 9:11 AM by gkaiseril

    concatenation fields

    evidal2 Level 1

      Hello and thank you all for your help in advance.

      My problem is this I have two fields 'name' and 'Surname' and I want to appear in another field together with a ',' separating the two.
      I wrote this at the option of calculating the final field but I do not work

       

       

       

      vname var = GetField('name');

      vsurname var = GetField('surname');

      vnamecomplet = GetField('namecomplet');

      vnamecomplet.value = vsurname.value + "," + vname.value;

       

       

       

       

      Thanks

        • 1. Re: concatenation fields
          MarkWalsh Level 4

          var vname = this.getField('name');

          var vsurname  = this.getField('surname');

          event.value = vsurname.value + ", " + vname.value;

           

           

          'var' needs to go before the variable name.

          'GetField' needs to be prefaced by 'this.', and the 'g' is not capitalized.

          Use 'event.value' to set the value for the Calculation (or Format, etc.).

           

          Open the Javascript Debugger will help to show you where your syntax is in error.

          1 person found this helpful
          • 2. Re: concatenation fields
            MarkWalsh Level 4

            Also, you might want to check to see if the contents of both fields is no empty as a condition to add the ', '

             

            Otherwise, you might end up with

             

            Smith,

             

            or

             

            , Bill

            • 3. Re: concatenation fields
              gkaiseril MVP & Adobe Community Professional

              Are you getting any errors in the Acrobat JavaScripbt debugging console?

               

              If you put the script in the 'namecomplet' field, you should use the 'event' object's 'value'

               

              You need to state the object being defined first and then supply the name and optional value

               

              var vname = getField('name');

               

              The method to obtain the a field object is 'getField()'.

               

              One should also reference the PDF document for the field, using 'this'.

               

              var vname = this.getField('name');

              var vsurname  = this.getField('surname');

              event.value = vsurname. + ", " + vname.;

               

              But this approach leaves a ',' in the field when there is not entry in either input field. So there are other changes you might want to implement. One can even create a user defined function to combine fields with an optional separator and automatically adjust for missing parameters.

              • 4. Re: concatenation fields
                evidal2 Level 1

                thanks but not working, I have your choice of rectification in
                calculation of the field I want to be the result and does not work.
                It's true, was an ornament but I do not need because I complicated things a lot for my level. I will continue trying to find a solution

                • 5. Re: concatenation fields
                  evidal2 Level 1

                  sorry was perfect, it was a typing error.

                  • 6. Re: concatenation fields
                    gkaiseril MVP & Adobe Community Professional

                    Sorry,

                     

                    The code should have read:

                     

                    var vname = this.getField('name').value;

                    var vsurname  = this.getField('surname').value;

                    event.value = vsurname + ", " + vname;