These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Trouble combining two text fields (First Name, Last Name)

poregon
Registered: Oct 27 2008
Posts: 80
Answered

I have a multi-page form that sometimes has an employee's name broken out as First and Last, and in other places, my employer wants them set as combined. Since the same name appears repeatedly on different pages, I have the Binding set to global so all they have to do is type the name in the first time and it auto-populates throughout the rest of the form.

I found one way to concatenate two text fields (TextField1.rawValue + " " + TextField2.rawValue;), but I've found it doesn't work if the fields I am trying to combine have binding set to Global and I have multiple instances of the field throughout several pages of the form (NameFirst[0].rawValue + .......). I've tried formatted.Value, too.
I'm really stuck here - I've searched every variation of the question that I can think of for several days, but can't find out how to do this -

Concatenate text fields that have Binding properties set to Global, with multiple instances of those fields in a form.

Anyone have a solution??

Thanks

poregon
Salix, Iowa

My Product Information:
LiveCycle Designer, Windows
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
I have been able to do this with the "Concat()" function, but you maybe having problems with subforms with same named fields but these fields are not linked to the 1st page. I would make one pair of first and last name fields for the data entry, and then use a 'exit' script to update all the other fields, which are read only.

George Kaiser

lsutton
Expert
Registered: Nov 15 2005
Posts: 51
Even with multiple global instances of the same name, just use the name without the number of the instance and you should be able to obtain the rawValue.

this.rawValue = fname.rawValue + " " + lname.rawValue;

Your calculate field only needs the calculate code once. It does not need to be repeated to the other instances with the same name if they are global.

Can you share an example of your problem via share.adobe.com?
poregon
Registered: Oct 27 2008
Posts: 80
I tried your suggestion, but I'm still not getting it to work.
Here's what I have -
First Name field is named NameFirst
Last" is named NameLast


New Text field (NameCombined) to combine them has the following code:
this.rawValue = NameFirst.rawValue + " " + NameLast.rawValue;
Show: Calculate
Language: JavaScript
Run at: Client

When I go to PDf preview and fill out the NameFirst and NameLast fields on page 1, the new NameCombined field continues to show blank -

What am i missing?
I'm waiting on an email confirmation from my Adobe ID sign in in order to share this on share.adobe.com
Thanks
poregon

poregon
Salix, Iowa

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
The following works for me with version 8.

----- form1.#subform[0].NameCombined[0]::calculate: - (JavaScript, client) ------------------------- if(NameFirst.rawValue != null & NameLast.rawValue!= null)$.rawValue = NameFirst.rawValue + " " + NameLast.rawValue;else$.rawValue = null;

George Kaiser

poregon
Registered: Oct 27 2008
Posts: 80
Thanks gkaiseril, but still no luck. I copied and pasted exactly as you have as the code for my NameComplete field -

form1.#subform[6].NameComplete::calculate - (JavaScript, client)
if(NameFirst.rawValue != null & NameLast.rawValue != null)
$.rawValue = NameFirst.rawValue + " " + NameLast.rawValue;
else
$.rawValue = null;

My NameFirst and NameLast is on (untitled Subform)(page1), and my NameComplete is on (untitled Subform)(page6), running 8.2.1.4029.1.523496

If I send you my email address, can you send me yours so I can possibly send you the file?

Thanks alot guys - this is a great learning experience for me.

poregon

poregon
Salix, Iowa

lsutton
Expert
Registered: Nov 15 2005
Posts: 51
This should do it for you:

if(xfa.resolveNode("#subform[0].NameFirst").rawValue != null & xfa.resolveNode("#subform[0].NameLast").rawValue != null)
{
this.rawValue = xfa.resolveNode("#subform[0].NameFirst").rawValue + " " + xfa.resolveNode("#subform[0].NameLast").rawValue;
}
else
{
this.rawValue = null;
}

One trick you may want to use when trying to access variables is the "Ctrl-click". Ctrl-click on the field that you would like to include in your code and the correct syntax to access that object should be inserted into your code for you.
poregon
Registered: Oct 27 2008
Posts: 80
Perfect - your solution worked great - thanks, sir, and thanks gkaiseril for telling me the same thing (I think), I just don't have enough knowledge yet to understand the unspoken nuances of JavaScript ($'s, !'s, etc). I love this forum, and I can't wait for the day that I can repay the kindness by actually helping someone else :)

poregon
Salix, Iowa

jean299
Registered: Nov 15 2009
Posts: 19
Greetings,

I'm using LiveCycle Designer 8.2.

In order to force a date format, I have added three drop down menus (day, month, year). The values are set for each item accordingly, eg, the value for May is 5, the value for 2010 is 10, etc.

Then I have a separate date field, which I have set as calculated read only, into which I want to see a concatenation of the three drop down fields. (e.g. --Day 15----Month May----Year 2010----becomes 15/05/10

For the date field I put in the following script, following the example above:

nswcerreferral.Page1.studentdetails.dob::calculate - (JavaScript, client)
if(xfa.resolveNode(dobday).rawValue != null & xfa.resolveNode(dobmonth).rawValue != null & xfa.resolveNode(dobyear).rawvalue != null)
{
this.rawValue = xfa.resolveNode(dobday).rawValue + "/" + xfa.resolveNode(dobmonth).rawValue + xfa.resolveNode(dobyear).rawValue;
}
else
{
this.rawValue = null;
}


The script doesn't seem to work when testing it on the preview tab in LiveCycle. The field just stays blank. Any help is much appreciated!

Regards,
jeannie
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
Do you get any error messages after editing the script, when entering preview, or on the JavaScript console?

You do not have a closing parenthesis on your 'if' statement.

George Kaiser

jean299
Registered: Nov 15 2009
Posts: 19
Thanks for getting back to me. I have solved the problem.

There was actually a closing parenthesis, no idea why it didn't show up in the copy and paste. Weird!

However, I did find I had left out the quote marks around the fields in the formula, so I put those in.

Then I was getting the right result in the date field, however, every time I entered a selection or change the selection in the drop down menus, I got an error warning "dob validate failed." The result was there and correct, but the warning popped up nevertheless.

I then removed the two slashes ------ +"/" ----- from between the three fields in the concatenation formula and voila, all's well.

I guess with the validation set for the date, the computer puts the slashes in for me and my adding them into the formula was confusing the poor thing!

Many thanks to those who have contributed to this good result.
jean299
Registered: Nov 15 2009
Posts: 19
Whoops!! I spoke too soon.

I had to manipulate the pattern to get the correct format dd/mm/yyyy and since doing that, I am once again getting the "dob validation failed" warning.

Also, I found the slashes were not automatically appearing any more so I put them back into the concatenation formula.

The results are there and correct, the field works correctly with another calculated field that uses it in a calculation. But I am still getting the validation failure warning.

Very annoying!! It all works, but still I get this warning?
jean299
Registered: Nov 15 2009
Posts: 19
OK, I found a chunk of javascript that I put into the validation script area and that seems to have made it work. I guess that overrides the automatic validation that was somehow not cooperating. Here is the javascript for the dd/mm/yyyy format:

/**
* DHTML date validation script for dd/mm/yyyy. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/datevalidation.asp)
*/
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
var i;
for (i = 0; i < s.length; i++){
// Check that current character is number.
var c = s.charAt(i);
if (((c < "0") || (c > "9"))) return false;
}
// All characters are numbers.
return true;
}

function stripCharsInBag(s, bag){
var i;
var returnString = "";
// Search through string's characters one by one.
// If character is not in bag, append to returnString.
for (i = 0; i < s.length; i++){
var c = s.charAt(i);
if (bag.indexOf(c) == -1) returnString += c;
}
return returnString;
}

function daysInFebruary (year){
// February has 29 days in any year evenly divisible by four,
// EXCEPT for centurial years which are not also divisible by 400.
return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
for (var i = 1; i <= n; i++) {
this[i] = 31
if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
if (i==2) {this[i] = 29}
}
return this
}

function isDate(dtStr){
var daysInMonth = DaysArray(12)
var pos1=dtStr.indexOf(dtCh)
var pos2=dtStr.indexOf(dtCh,pos1+1)
var strDay=dtStr.substring(0,pos1)
var strMonth=dtStr.substring(pos1+1,pos2)
var strYear=dtStr.substring(pos2+1)
strYr=strYear
if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
for (var i = 1; i <= 3; i++) {
if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
}
month=parseInt(strMonth)
day=parseInt(strDay)
year=parseInt(strYr)
if (pos1==-1 || pos2==-1){
alert("The date format should be : dd/mm/yyyy")
return false
}
if (strMonth.length<1 || month<1 || month>12){
alert("Please enter a valid month")
return false
}
if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
alert("Please enter a valid day")
return false
}
if (strYear.length != 4 || year==0 || yearmaxYear){
alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
return false
}
if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
alert("Please enter a valid date")
return false
}
return true
}

function ValidateForm(){
var dt=document.frmSample.txtDate
if (isDate(dt.value)==false){
dt.focus()
return false
}
return true
}

jean299
Registered: Nov 15 2009
Posts: 19
Sorry I deleted a double post here.
jean299
Registered: Nov 15 2009
Posts: 19
Good grief!!

I noticed that the javascript didn't prevent me from putting in Feb 29th in non leap years, as it is supposed to do. And, I wanted to get away from the need for all that script.

So I kept playing around with it and have discovered that if I change the locale to Australia, everything works with no problem. No mysterious validation warning.

My computer defaults are all set to Australia, but still this change seems to have put the validation right, at last!!