Highlighted

Populate a text field depending on text contained in another text field

New Here ,
Sep 23, 2020

Copy link to clipboard

Copied

I have a text field named ReportNumber_TB. Users of my form will enter an alphanumeric code in ReportNumber_TB that includes employee initials.

 

I have another text field named ContactInfo_TB. I need ContactInfo_TB to automatically populate the full name and email address associated with the employee initials that were entered in ReportNumber_TB.

 

For example:

if ReportNumber_TB contains “AAA” then ContactInfo_TB populates with “Alice Adams, AAA@email.com

if ReportNumber_TB contains “BBB” then ContactInfo_TB populates with “Bruce Banner, BBB@email.com

if ReportNumber_TB contains “CCC” then ContactInfo_TB populates with “Chris Carter, CCC@email.com

if ReportNumber_TB contains “DDD” then ContactInfo_TB populates with “Dan Davis, DDD@email.com

 

What script can I use to do this? I’ve searched but can’t find anything to try that’s similar enough to what I need to accomplish. 

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

As the custom calculation script of the second field enter the following code:

 

var v = this.getField("ReportNumber_TB").valueAsString;
if (/AAA/.test(v)) event.value = "Alice Adams, AAA@email.com";
else if (/BBB/.test(v)) event.value = "Bruce Banner, BBB@email.com"; // etc.
else event.value = "";
TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

51

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

Populate a text field depending on text contained in another text field

New Here ,
Sep 23, 2020

Copy link to clipboard

Copied

I have a text field named ReportNumber_TB. Users of my form will enter an alphanumeric code in ReportNumber_TB that includes employee initials.

 

I have another text field named ContactInfo_TB. I need ContactInfo_TB to automatically populate the full name and email address associated with the employee initials that were entered in ReportNumber_TB.

 

For example:

if ReportNumber_TB contains “AAA” then ContactInfo_TB populates with “Alice Adams, AAA@email.com

if ReportNumber_TB contains “BBB” then ContactInfo_TB populates with “Bruce Banner, BBB@email.com

if ReportNumber_TB contains “CCC” then ContactInfo_TB populates with “Chris Carter, CCC@email.com

if ReportNumber_TB contains “DDD” then ContactInfo_TB populates with “Dan Davis, DDD@email.com

 

What script can I use to do this? I’ve searched but can’t find anything to try that’s similar enough to what I need to accomplish. 

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

As the custom calculation script of the second field enter the following code:

 

var v = this.getField("ReportNumber_TB").valueAsString;
if (/AAA/.test(v)) event.value = "Alice Adams, AAA@email.com";
else if (/BBB/.test(v)) event.value = "Bruce Banner, BBB@email.com"; // etc.
else event.value = "";
TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

52

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
Sep 23, 2020 0
Most Valuable Participant ,
Sep 23, 2020

Copy link to clipboard

Copied

As the custom calculation script of the second field enter the following code:

 

var v = this.getField("ReportNumber_TB").valueAsString;
if (/AAA/.test(v)) event.value = "Alice Adams, AAA@email.com";
else if (/BBB/.test(v)) event.value = "Bruce Banner, BBB@email.com"; // etc.
else event.value = "";

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
Reply
Loading...
Sep 23, 2020 0
New Here ,
Sep 23, 2020

Copy link to clipboard

Copied

It works! Thank you!

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
Reply
Loading...
Sep 23, 2020 0