Get Text from Two Fields to Show in Third Field

New Here ,
Apr 24, 2020 Apr 24, 2020

Copy link to clipboard

Copied

I have three fields: CALicense, ARLicense, and AgentLicense.

I would like AgentLicence to show text from either/both CA and AR License fields depending on which is entered. I’m getting lost on the if condition part of the script – I’m thinking that a check for empty fields is necessary…? Here's the direction I'm thinking of:

 

var lic1 = this.getField(“CALicense”).value;

var lic2 = this.getField(“ARLicense”).value;

 

if (lic1 = “” && lic2 = “”){

event.value = “”;

}

if (CALicense has text but not ARLicense){

event.value = “CA License #” + lic1;

}

If (RALicense has text but not CALicense){

event.value = “ARLicense #) + lic2;

}

If (both CALicense and ARLicense both have text)}

event.value = “CA License #” + lic1 + “ & ARLicense #” + lic2;

}

TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

97

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Apr 25, 2020 Apr 25, 2020

Copy link to clipboard

Copied

Hi,

 

 

You can try the code below. Note that I fixed a few things, like spacing, proper syntax, and the use of quotes.

 

Ensure that the quotes that you're using are straight. Javascript may misinterpret it if a different font type is used.

 

Just copy the script below and use it as the custom calculation script of the Agent License text field.

 

 

 

var lic1 = this.getField("CALicense").valueAsString;
var lic2 = this.getField("ARLicense").valueAsString;

if (lic1 && lic2 =="") event.value ="";
else if ((lic1 !="") && (lic2 =="")) event.value = "CA License # " + lic1;
else if ((lic2 != "") && (lic1 =="")) event.value = "ARLicense # " + lic2;
else if (lic1 && lic2 != "") event.value = "CA License # " + lic1 + " & ARLicense # " + lic2;

 

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Apr 25, 2020 Apr 25, 2020

Copy link to clipboard

Copied

I apologize, please disregard my prior reply.  I did a mistake in the code example.

 

This is what is working on my end:

 

var d = this.getField("CALicense").valueAsString;
var e = this.getField("ARLicense").valueAsString;
var f = this.getField("AgentLicense").valueAsString;

if ( (d != "") && (e === "") ) event.value = " CA License " + d;
else if ( (e != "") && (d === "") ) event.value = " AR License " + e;
else if ( (d != "") && (e != "") ) event.value = " CA License " + d + " AR License ";

else if ( (e === "") && (d === "") ) event.value = this.resetForm(["AgentLicense"]);

 

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 26, 2020 Apr 26, 2020

Copy link to clipboard

Copied

Thank you so much!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Apr 27, 2020 Apr 27, 2020

Copy link to clipboard

Copied

LATEST

You're welcome

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines