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

How do I use the same function more than once on the same page?

Community Beginner ,
Jul 02, 2019 Jul 02, 2019

Copy link to clipboard

Copied

I reviewed this tutorial: https://acrobatusers.com/tutorials/change_another_field  and it works great, but I need to create 15 more drop downs to do the same thing. How do I do this? The example in the above link only shows how to create once instance.

TOPICS
Acrobat SDK and JavaScript , Windows

Views

1.3K

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 ,
Jul 02, 2019 Jul 02, 2019

Copy link to clipboard

Copied

Do all of the drop-downs need to populate the same fields, or is it a different one each time?

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 ,
Jul 02, 2019 Jul 02, 2019

Copy link to clipboard

Copied

Hello,
Thank you for your reply. I need to duplicate the same function multiple times. I have attached a screen capture of how I need to duplicate. Pretty much the exact same thing, 15 times.2019-07-02_16-59-38.png
Thanks again!

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 ,
Jul 02, 2019 Jul 02, 2019

Copy link to clipboard

Copied

It's not the same thing, because each drop-down needs to populate a different text field. To do that you would need to either create a separate function for each drop-down, or use the same function but pass the name of the fields to populate as parameters, as explained above.

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 ,
Jul 02, 2019 Jul 02, 2019

Copy link to clipboard

Copied

I know... this is what I tried. I have not dealt with Javascript in many years.

Main Document Script:

// Place all prepopulation data into a single data structure

var DeptData = { "Select":{ fundcode: "" },

                 "TD Greystone Mortgage and Short Bond Pooled Fund Trust A":{ fundcode: "TDB 2170" },

                 "TD Greystone Mortgage and Short Bond Pooled Fund Trust B":{ fundcode: "TDB 2171" }};

function SetFieldValues(cDeptName)

{

  this.getField("FundCode1").value = DeptData[cDeptName].fundcode;

}

var DeptData = { "Select":{ fundcode2: "" },

                 "TD Greystone Mortgage and Short Bond Pooled Fund Trust A":{ fundcode2: "TDB 2170" },

                 "TD Greystone Mortgage and Short Bond Pooled Fund Trust B":{ fundcode2: "TDB 2171" }};

function SetFieldValues(cDeptName2)

{

  this.getField("FundCode2").value = DeptData[cDeptName2].fundcode2;

}

Second Drop Down Script (Custom Keystroke Script):

if( event.willCommit )

{

   if(event.value == " ")

     this.resetForm(["FundCode2"]);

   else

     SetFieldValues(event.value);

}

And under the GENERAL tab for that drop down I have FundName2

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 ,
Jul 02, 2019 Jul 02, 2019

Copy link to clipboard

Copied

No, that's not how you should do it. Are the values in the drop-downs the same? If so, you only need one data model (the DeptData variable).

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 ,
Jul 02, 2019 Jul 02, 2019

Copy link to clipboard

Copied

So something like this?

// Place all prepopulation data into a single data structure

var DeptData = { "Select":{ fundcode: "" },

                 "TD Greystone Mortgage and Short Bond Pooled Fund Trust A":{ fundcode: "TDB 2170" },

                 "TD Greystone Mortgage and Short Bond Pooled Fund Trust B":{ fundcode: "TDB 2171" }};

function SetFieldValues(cDeptName)

{

  this.getField("FundCode1").value = DeptData[cDeptName].fundcode;

}

{

  this.getField("FundCode2").value = DeptData[cDeptName].fundcode;

}

That still does not work.

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 ,
Jul 03, 2019 Jul 03, 2019

Copy link to clipboard

Copied

Saying "it does not work" is not very helpful to us. In what way is it not working, exactly?

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 ,
Jul 03, 2019 Jul 03, 2019

Copy link to clipboard

Copied

You need only one function:

function SetFieldValues(cDeptName, targetField)

{

  this.getField(targetField).value = DeptData[cDeptName].fundcode;

}

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 ,
Jul 03, 2019 Jul 03, 2019

Copy link to clipboard

Copied

Hello,
Sorry not sure what you mean by using that one function? I tried that as well and it was not working. I have posted the file here: http://media.campaigner.com/media/57/579345/Subscription_Agreement_EN_fillable%20V7%20-%20UPDATE.pdf  if you are able to take a took it would be GREATLY appreciated! 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
Community Expert ,
Jul 03, 2019 Jul 03, 2019

Copy link to clipboard

Copied

Under the code of "FundName1", change this line:

SetFieldValues(event.value)

To:

SetFieldValues(event.value, "FundCode1")

And under the second field change it to:

SetFieldValues(event.value, "FundCode2")

etc.

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 ,
Jul 03, 2019 Jul 03, 2019

Copy link to clipboard

Copied

I think I am almost there! I have this script for the drop downs:

if( event.willCommit )

{

   if(event.value == " ")

     this.resetForm(["FundCode1"]);

   else

     SetFieldValues(event.value, "FundCode1")

}

and

if( event.willCommit )

{

   if(event.value == " ")

     this.resetForm(["FundCode2"]);

   else

     SetFieldValues(event.value, "FundCode2")

}

and for the page script:

var DeptData = { "Select":{ fundcode: "" },

                 "TD Greystone Mortgage and Short Bond Pooled Fund Trust A":{ fundcode: "TDB 2170" },

                 "TD Greystone Mortgage and Short Bond Pooled Fund Trust B":{ fundcode: "TDB 2171" }};

function SetFieldValues(cDeptName, targetField) 

  this.getField(targetField).value = DeptData[cDeptName].fundcode; 

}

But only the first drop down is working. I have reposted the file here:

http://media.campaigner.com/media/57/579345/Subscription_Agreement_EN_fillable%20V7%20-%20UPDATE.pdf

I can't figure out where I am going wrong here...

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 ,
Jul 03, 2019 Jul 03, 2019

Copy link to clipboard

Copied

In the drop downs you must use:

SetFieldValues(event.value, "FundCode1");

SetFieldValues(event.value, "FundCode2");

and so on

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 ,
Jul 03, 2019 Jul 03, 2019

Copy link to clipboard

Copied

I think I am almost there! I have this script for the drop downs:

if( event.willCommit )

{

   if(event.value == " ")

     this.resetForm(["FundCode1"]);

   else

     SetFieldValues(event.value, "FundCode1")

}

and

if( event.willCommit )

{

   if(event.value == " ")

     this.resetForm(["FundCode2"]);

   else

     SetFieldValues(event.value, "FundCode2")

}

and for the page script:

var DeptData = { "Select":{ fundcode: "" },

                 "TD Greystone Mortgage and Short Bond Pooled Fund Trust A":{ fundcode: "TDB 2170" },

                 "TD Greystone Mortgage and Short Bond Pooled Fund Trust B":{ fundcode: "TDB 2171" }};

function SetFieldValues(cDeptName, targetField)

{

  this.getField(targetField).value = DeptData[cDeptName].fundcode;

}

But only the first drop down is working. I have reposted the file here:

http://media.campaigner.com/media/57/579345/Subscription_Agreement_EN_fillable%20V7%20-%20 UPDATE.pd...

I can't figure out where I am going wrong here...

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 ,
Jul 03, 2019 Jul 03, 2019

Copy link to clipboard

Copied

This is the same old form.

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 ,
Jul 03, 2019 Jul 03, 2019

Copy link to clipboard

Copied

Sorry... the system renamed and cached the file. Here is the updated version:

http://media.campaigner.com/media/57/579345/UPDATED2.pdf

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 ,
Jul 03, 2019 Jul 03, 2019

Copy link to clipboard

Copied

The entry "TD Emerald Private/Public Debt Pooled Fund Trust – F" is not available in DeptData:

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 ,
Jul 03, 2019 Jul 03, 2019

Copy link to clipboard

Copied

LATEST

AWESOME!!! That was it! Thank you both for helping out so much!

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 ,
Jul 02, 2019 Jul 02, 2019

Copy link to clipboard

Copied

Are the other 15 instances using the same information in the 2nd field? There are a number of ways you can approach this. The more you know about JavaScript, the easier it will be for you. The way I would handle this is to create a document level script with a function that will change the information in the 2nd field based on the first field. You can e.g. pass in the two field names as parameters to the function:

function change2ndField(sourceName, targetName) {

    // ....

}

You can then just call that function with the pair of field names:

// ...

change2ndFieldName("TheFirstField", "TheSecondField");

// ...

For this to work, you need to be familiar with creating JavaScript functions.

If that is not possible, the most straight forward approach (but the one that requires the most typing) is to just duplicate the code for each pair of fields. You just have to make sure that you change any reference to a field name so that the script links up the correct two fields.

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