Skip to main content
Participating Frequently
December 6, 2024
Answered

Auto populate textboxes from another field value not working when I add another similar script

  • December 6, 2024
  • 3 replies
  • 776 views

I have two different combo boxes that are supposed to fill separate text fields. And they both work fine, unless I add both codes at the same time. One of them just stops working.

I don't really know javascript, I followed a tutorial to set them. But I don't know how to make both work. Can someone help me?

 

These are my two scripts:

 

var ComboBox1Data =
{ "Example1":{ description: "blah blah",
type: "blah blah",
cost: "blah blah" },
"Example2":{ description: "blah blah",
type: "blah blah",
cost: "blah blah" }};
function SetFieldValues(cComboBox1)
{
this.getField("ExampleDes").value = ComboBox1Data[cComboBox1].description;
this.getField("ExampleType").value = ComboBox1Data[cComboBox1].type;
this.getField("ExampleCost").value = ComboBox1Data[cComboBox1].cost;
}

 

////

var ComboBox2Data =
{ "Example3":{ name: "blah blah",
part: "blah blah" },
"Example4":{ name: "blah blah",
part: "blah blah" }};
function SetFieldValues(cComboBox2)
{
this.getField("ExampleName").value = ComboBox2Data[cComboBox2].name;
this.getField("ExamplePart").value = ComboBox2Data[cComboBox2].part;
}

 

This topic has been closed for replies.
Correct answer Thom Parker

You did a great job of setting up the scripts for two different comboboxes.  

But missed one detail. You can't have two functions with the same name. 

The SetFieldValues function needs to be renamed for the different uses. 

So, "SetFieldValues1" and "SetFieldValues2". 

 

 

3 replies

PDF Automation Station
Community Expert
Community Expert
December 6, 2024

You are using the same function name so the second function is overwriting the first.  Change the name of one of the functions and change it where you're calling it from.

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
December 6, 2024

You did a great job of setting up the scripts for two different comboboxes.  

But missed one detail. You can't have two functions with the same name. 

The SetFieldValues function needs to be renamed for the different uses. 

So, "SetFieldValues1" and "SetFieldValues2". 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participating Frequently
December 6, 2024

I have actually tried that, but it still overwrites the other. Do I have to change the name anywhere else inside the script?

Thom Parker
Community Expert
Community Expert
December 6, 2024

You are probably just missing a small detail. For example, are the different functions used in the different comboboxes?

Small details count with any kind of programming.

Can you post your form, or at least a demo form with the functionality in it?

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
PDF Automation Station
Community Expert
Community Expert
December 6, 2024

Where are the scripts located?

Participating Frequently
December 6, 2024

In javascript functions as: SetFieldValues

I followed this tutorial: https://acrobatusers.com/tutorials/change_another_field/