Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Get Text from Two Fields to Show in Third Field

New Here ,
Apr 24, 2020 Apr 24, 2020

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
626
Translate
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

correct answers 1 Correct answer

Community Expert , Apr 25, 2020 Apr 25, 2020

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 
...
Translate
Community Expert ,
Apr 25, 2020 Apr 25, 2020

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;

 

 

Translate
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
Community Expert ,
Apr 25, 2020 Apr 25, 2020

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"]);

 

 

Translate
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

Thank you so much!

Translate
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
Community Expert ,
Apr 27, 2020 Apr 27, 2020
LATEST

You're welcome

Translate
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