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

Show fields based on text entry

Community Beginner ,
Apr 29, 2024 Apr 29, 2024

Hello, I want to create a form where a user can type a product code on a text field and show 3 other text fields which are (description of the current product code, competitor A's product, comptetitor B's product)

 

I've come across this tutorial and it's close to what I want to do, but instead of the drop-down I want to be able to type in the value in a text field and the relevant info would show up.

 

Follow up question, I have over a hundred product codes to add so I'm not sure if this is the best way to do it but I figure I'd start here, thanks

TOPICS
How to , JavaScript , PDF , PDF forms
567
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
1 ACCEPTED SOLUTION
Community Expert ,
Apr 29, 2024 Apr 29, 2024

You can use this as 'Validate' script of 'Code' field, assuming 3 fields are named "Competitor A,B and C", just fill in 'cList' with your data nothing else needs to be changed:

var cList = [
{code: "001", cA:"Description for competitor A", cB:"Description for competitor B", cC:"Description for competitor C"},
{code: "002", cA:"Description for competitor A", cB:"Description for competitor B", cC:"Description for competitor C"},
{code: "003", cA:"Description for competitor A", cB:"Description for competitor B", cC:"Description for competitor C"}];

function updateFields(selectedCode) {
 var found = false;

 for (var i = 0; i < cList.length; i++) {
  if (selectedCode === cList[i].code) {
   this.getField("Competitor A").value = cList[i].cA;
   this.getField("Competitor B").value = cList[i].cB;
   this.getField("Competitor C").value = cList[i].cC;
   found = true;
   break;}}

  if (!found) {
   this.getField("Competitor A").value = "";
   this.getField("Competitor B").value = "";
   this.getField("Competitor C").value = "";}}

updateFields(event.value);

View solution in original post

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 29, 2024 Apr 29, 2024

You can use this as 'Validate' script of 'Code' field, assuming 3 fields are named "Competitor A,B and C", just fill in 'cList' with your data nothing else needs to be changed:

var cList = [
{code: "001", cA:"Description for competitor A", cB:"Description for competitor B", cC:"Description for competitor C"},
{code: "002", cA:"Description for competitor A", cB:"Description for competitor B", cC:"Description for competitor C"},
{code: "003", cA:"Description for competitor A", cB:"Description for competitor B", cC:"Description for competitor C"}];

function updateFields(selectedCode) {
 var found = false;

 for (var i = 0; i < cList.length; i++) {
  if (selectedCode === cList[i].code) {
   this.getField("Competitor A").value = cList[i].cA;
   this.getField("Competitor B").value = cList[i].cB;
   this.getField("Competitor C").value = cList[i].cC;
   found = true;
   break;}}

  if (!found) {
   this.getField("Competitor A").value = "";
   this.getField("Competitor B").value = "";
   this.getField("Competitor C").value = "";}}

updateFields(event.value);
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 Beginner ,
Apr 30, 2024 Apr 30, 2024

Hi Nesa, 

This is great it worked for me (just changed Code to selectedCode)

Thank you!

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 Beginner ,
Jun 02, 2025 Jun 02, 2025

Hi Nesa, 

 

I've just discovered that this doesn't work on iPhone, can you please advise?

 

I have tested the PDF on PC and MAC and they both work fine, I type in a code on one field and the other fields are pre-polulated with texts, but for some reason the script doesn't work on iPhone.

 

KR

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
Adobe Employee ,
Jun 02, 2025 Jun 02, 2025
LATEST

Hello @studiom50222188!

 

Thanks for reaching out. We have answered your question in the other thread you initiated: https://adobe.ly/3Zfk2v0

 

As stated, the current functionality you are looking for is not supported on a Mobile device with Acrobat Reader.

 

I hope this helps.

Thanks,

Anand Sri.

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