Copy link to clipboard
Copied
I would like to auto-populate a field in Adobe using the first & last names of the people completing the form as per the following:
DETAILS ENTERED BY CLIENTS ON PAGE ONE
FIELD I NEED TO AUTO POPULATE
I am using the following custom calculation script to auto populate "authorisation_1", which works fine when the "firstname2" and "lastname2" fields have been populated:
event.value = getField("firstname1").valueAsString + " " + getField("lastname1").valueAsString + " & " + getField("firstname2").valueAsString + " " + getField("lastname2").valueAsString;
However, my question is, how do i ensure the "&" does not appear in "authorisation_1" field IF nothing has been entered into the "firstname2" and "lastname2" fields?
NEED TO AVOID THIS
Thanks in advance.
HI,
You may declare variables instead of using the long typing method to make your script more organized and easier to read as an equation if you want (but this just my preference).
Then add an IF/ELSE condition to your custom calculatiopn script. It could be something like this, for example:
var name1 = getField("firstname1").valueAsString;
var last1 = getField("lastname1").valueAsString;
var name2 = getField("firstname2").valueAsString;
var last2 = getField("lastname2").valueAsString;
if (
...
Copy link to clipboard
Copied
HI,
You may declare variables instead of using the long typing method to make your script more organized and easier to read as an equation if you want (but this just my preference).
Then add an IF/ELSE condition to your custom calculatiopn script. It could be something like this, for example:
var name1 = getField("firstname1").valueAsString;
var last1 = getField("lastname1").valueAsString;
var name2 = getField("firstname2").valueAsString;
var last2 = getField("lastname2").valueAsString;
if ( ( (name1 !="") && (last1 !="") ) && ( (name2 !="") && (last2 !="") ) ) event.value = name1+" "+last1+ " & " + name2+ " "+last2;
else event.value = name1+" "+last1;
Copy link to clipboard
Copied
Hi ls_rbls,
This suggestion worked perfectly... thank you.
Copy link to clipboard
Copied
You're welcome.
Copy link to clipboard
Copied
Hi,
The above answer is correct but could be simplified a little as we always return name1 and last1, so the code could be
var finalString = getField("firstname1").valueAsString + " " + getField("lastname1").valueAsString;
var name2 = getField("firstname2").valueAsString;
var last2 = getField("lastname2").valueAsString;
if ( name2 !="" && last2 !="" ) {
finalString += " & " + name2+ " "+last2;
}
event.value = finalString;
Regards
Malcolm
Copy link to clipboard
Copied
Nice!
Thank you.
Copy link to clipboard
Copied
Hi,
Look at line 2 and remove:
+ "&"
It should work fine.
Good Luck