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

If/Then based on reference field

Community Beginner ,
Apr 18, 2023 Apr 18, 2023

New here, so I apologize if I don't follow proper procedure. Thank you, Thom Parker, for your assistance and I apologize for the delayed check on correct answer from previous question. I have another question regarding my project. Attached are two pages from my project.

 

Goals:

  • To auto populate Name, Agency, Phone, and Email based on drop down list in far-left column (Position) on page 2.
  • To utilize same function script (Name, Agency, Phone, Email) for all rows by using split shift to use Row# reference instead of a separate function for each row.

 

Document: 

  • Pg 1 only has 10 rows for reference for testing
  • Pg. 2 only has one row with one (Name, Agency, Phone, & Email) for testing

 

I am not having any luck with the script below to populate name based on listed position. Suggestions?

 

////Script Name: ICS-205A drop

function DoNameReferencePosition()

{

var cRowName = event.target.name.split(".").shift();

var fieldB = this.getField(cRowName + ".205A DropA").value;

if (fieldB == this.getField("Row1.Position").value) event.value = this.getField("Row1.Name").value;

else if (fieldB == this.getField("Row2.Position").value) event.value =  this.getField("Row2.Name").value;

else if (fieldB == this.getField("Row3.Position").value) event.value =  this.getField("Row3.Name").value;

else if (fieldB == this.getField("Row4.Position").value) event.value =  this.getField("Row4.Name").value;

else if (fieldB == this.getField("Row5.Position").value) event.value =  this.getField("Row5.Name").value;

else if (fieldB == this.getField("Row6.Position").value) event.value =  this.getField("Row6.Name").value;

else if (fieldB == this.getField("Row7.Position").value) event.value =  this.getField("Row7.Name").value;

else if (fieldB == this.getField("Row8.Position").value) event.value =  this.getField("Row8.Name").value;

else if (fieldB == this.getField("Row9.Position").value) event.value =  this.getField("Row9.Name").value;

else if (fieldB == this.getField("Row10.Position").value) event.value =  this.getField("Row10.Name").value;

else if (fieldB =="") event.value="";

}

TOPICS
Create PDFs , Edit and convert PDFs , General troubleshooting , How to , JavaScript , PDF forms
1.6K
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 19, 2023 Apr 19, 2023

Change the value of any field and then check the JS Console. There are errors in your code.

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 19, 2023 Apr 19, 2023

The code is not correct. What is the if statement ".Position" equals then statement ".Name" using ".205A DropA” as the reference is recommended?

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 19, 2023 Apr 19, 2023

It appears that you are attempting to implement somewhat complicated functionality. In this case, copying data from one table into another based on a dropdown selection. But there is obviously other complex behaviors as well, such as filling in the items in the dropdown. These should really come from the first column in the first table, not the "ListItems" field. 

 

In order implement this complex behavior, and to fix the code on your form you'll need to do a couple of things. First, it is a really good idea to spend some time learning core JavaScript. Any time spent up front leaning the basics will be paid back many times. Second, you need to fix the easy errors before asking us for help. For example, there are many "this.getField()" calls that specify non-existant field names. Clear these up first. Next, you've done a good job of naming the fields in the tables, use these names make the coding simpler. This is the type of thing you should be asking us about. 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 19, 2023 Apr 19, 2023
LATEST

Thank you for the feed back. I'll go back and try to learn more.

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