6 Replies Latest reply on Jun 28, 2015 8:09 AM by Branchard0902

    Split Name Field Into Two Fields

    Branchard0902

      Hi There -

       

      I have a form that has a single name field for First and Last name. I then have another page that asks for the names to be separated into two fields. Can this be done?

       

      And can I then pull the first initial of both names and place it into another form field?

       

      Thanks,

      Brandy

        • 1. Re: Split Name Field Into Two Fields
          try67 MVP & Adobe Community Professional

          Technically it's quite simple to do it, but I would recommend you to avoid doing it for cultural reasons.

          Many people in various cultures have multiple first and/or last names, as well as middle names, initials in their names, etc.

          The chances of you getting it right 100% of the time is slim and if you get it wrong someone can be seriously pissed off that you screwed up their name.

          If you really want to do it then do it the other way around: Let them fill in their first and last name(s) in separate fields and then combine them into a single "Full Name" field automatically. There are less chances of screwing it up then, although it's still possible: Imagine someone called "John Doe III", ie "John Doe the Third". Their family name is not "Doe III", just "Doe", while their first name is not really "Joe III", either, but if they fill that in the First Name field the result in the combined field will be "Joe III Doe"...

          • 2. Re: Split Name Field Into Two Fields
            Karl Heinz Kremer Adobe Community Professional

            I can - from personal experience - confirm what try67 stated: My name has three parts, two of them are my first name, and one is my last name. You cannot image what types of name abuse I have to deal with on almost a daily basis. Do not try to automate splitting a name into it's parts, people like me will thank you for that

            • 3. Re: Split Name Field Into Two Fields
              Branchard0902 Level 1

              While I do appreciate your advice, the name field I want to split is a field only used by internal staff. I know that only 4 people will be filling out this form and none of them have multiple names. So I would still like to know how to split it. And I would like to be able to pull their two initials and put into another field. Can someone please help? Thanks!

              • 4. Re: Split Name Field Into Two Fields
                gkaiseril MVP & Adobe Community Professional

                I would design the form with individual fields for the first and last names and then have 3rd field that combines them.

                 

                In Acrobat 5.0 Adobe introduced the concept of Personal Field Names, PFN, were one would enter the individual pieces of a field like name, address, phone number, etc. and the pieces for a single field would combined into one field is common document and then the common document's fields would be exported to an FDF file which could then be imported into another PDF and as long as there were fields with some of the  same field names those field's would be populated with the data  from the FDF.

                • 5. Re: Split Name Field Into Two Fields
                  try67 MVP & Adobe Community Professional

                  Assuming each name is composed of two words only, you can use this code as the custom calculation script of the First Name field:

                  var fullName = this.getField("Full Name").valueAsString;
                  if (fullName=="") event.value = "";
                  else event.value = fullName.split(" ")[0];
                  
                  
                  

                  Replace [0] with [1] for the Last Name field.

                   

                  For the initials field you can use this code:

                  var fullName = this.getField("Full Name").valueAsString;
                  if (fullName=="") event.value = "";
                  else {
                       var words = fullName.split(" ");
                       for (var i in words) words[i]=words[i].substring(0,1);
                       event.value = words.join(".");
                  }
                  
                  
                  

                   

                  Edit: Fixed mistake in location of script