Skip to main content
jeffreyg26558119
Known Participant
July 2, 2019
Question

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

  • July 2, 2019
  • 2 replies
  • 2405 views

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.

This topic has been closed for replies.

2 replies

Karl Heinz  Kremer
Community Expert
Community Expert
July 2, 2019

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.

try67
Community Expert
Community Expert
July 2, 2019

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

jeffreyg26558119
Known Participant
July 2, 2019

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.
Thanks again!

try67
Community Expert
Community Expert
July 2, 2019

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.