Skip navigation
JWsf
Currently Being Moderated

Combining 2 text fields to create a third field

Apr 21, 2012 11:22 AM

Hi all

I am new to the Adobe arena so I hope that some one can please lead me to accomplish this task.

I have 2 text fields last name & first name

I would like to have it create a third field with the last name, (first character of the first name field) and placing a comma after the last name.

Thank you

James

 
Replies
  • Currently Being Moderated
    Apr 22, 2012 4:02 PM   in reply to JWsf

    Hi,

     

    You would place the script in the calculate event of the third field.

     

    This should get you close (you will need to change the object references to suit the names of your objects):

     

    I will use JavaScript:

     

    if (lastName.rawValue !== null && firstName.rawValue !== null) {
         this.rawValue = lastName.rawValue + ", " + firstName.rawValue.toString().slice(0,1); 
    }
    

     

    You may not need the .toString() bit, but give it a try.

     

    Niall

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 22, 2012 5:18 PM   in reply to JWsf

    Sounds like you are designing your form in Acrobat and NOT LC Designer. Is that correct?

     

    AcroForms use a slightly different syntax (closer to Core JavaScript).

     

    Niall

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 22, 2012 11:42 PM   in reply to JWsf

    Hi James,

     

    Yes, it does. LC Designer creates different forms and has different JavaScript syntax. You are in the LC Designer forum and your query may be better answered in an Acrobat forum.

     

    The following script should work in an AcroForm (fingers crossed):

     

    var i = this.getField("firstName"); 
    var j = this.getField("lastName"); 
    var k = this.getField("combinedName"); 
    
    if (i.value !== null && j.value !== null) {
         k.value = j.value + ", " + i.value.toString().slice(0,1); 
    }
    

     

    As before, you will need to change the object references to suit your form.

     

    Hope that helps,

     

    Niall

     
    |
    Mark as:
  • George Johnson
    11,661 posts
    Aug 11, 2002
    Currently Being Moderated
    Apr 23, 2012 1:18 AM   in reply to Niall O\'Donovan

    I revised Niall's script some to make it work as a custom calculation script and make it a bit more suitable for an Acroform:

     

    // Get the field values, as strings
    var i = this.getField("firstName").valueAsString; 
    var j = this.getField("lastName").valueAsString; 
    
    // Set this field's value if both fields are not blank
    // otherwise, set this field to blank 
    if (i && j) {
         event.value = j + ", " + i.slice(0, 1); 
    } else {
         event.value = "";
    }
    

     

    (An acroform field value will never be equal to null.)

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 23, 2012 1:33 AM   in reply to George Johnson

    Thanks George!

     
    |
    Mark as:
  • George Johnson
    11,661 posts
    Aug 11, 2002
    Currently Being Moderated
    Apr 25, 2012 10:05 PM   in reply to JWsf

    The code posted assumes your fields are named "firstName" and"lastName". If your fields are named something else, you'll have to use the exact field names. You can also check for errors in the JavaScript console (Ctrl+j). It is written to be a custom calculate script, so make sure it's in the right place. It will get triggered whenever any field value changes.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points