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

Show fields based on text entry

Community Beginner ,
Apr 29, 2024 Apr 29, 2024

Copy link to clipboard

Copied

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

Views

211

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
1 ACCEPTED SOLUTION
Community Expert ,
Apr 29, 2024 Apr 29, 2024

Copy link to clipboard

Copied

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

Votes

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

Copy link to clipboard

Copied

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

Votes

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
Community Beginner ,
Apr 30, 2024 Apr 30, 2024

Copy link to clipboard

Copied

LATEST

Hi Nesa, 

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

Thank you!

Votes

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