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

How to run multiple javascripts in one pdf fillable form

New Here ,
Feb 04, 2021 Feb 04, 2021

I've built 3 different javascripts for my fillable pdf document for 3 different sets of boxes, but it will only run one of those scripts and the other two won't work. How can I get all 3 to work on the same pdf? I'm using a drop down in each of the 3 boxes that will then populate 4 other boxes with information using a javascript (see picture below...this is one of the 3). But again, it will only work on one of the three.

Any help would be most appreciated!

Cambria5CAC_0-1612455433186.png

 

TOPICS
JavaScript , PDF forms
2.2K
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 ,
Feb 04, 2021 Feb 04, 2021

What script does you use? Where does you use the script?

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
New Here ,
Feb 04, 2021 Feb 04, 2021

I've placed 'x' where numbers would normally be in my script to protect the information.

var data =

{items:[

        {key : "North Direct", value1 : "RX: xxx.xxxx", value2 : "RX Tone 000.0", value3 : "TX: xxx.xxxx", value4 : "TX Tone 000.0"},

        {key : "Deadman RPT", value1 : "RX: xxx.xxxx", value2 : "RX Tone 000.0", value3 : "TX: xxx.xxxx", value4 : "TX Tone xxx.x"},

        {key : "Jelm RPT", value1 : "RX: xxx.xxxx", value2 : "RX Tone 000.0", value3 : "TX: xxx.xxxx", value4 : "TX Tone xxx.x"},

        {key : "Buckhorn RPT", value1 : "RX: xxx.xxxx", value2 : "RX Tone 000.0", value3 : "TX: xxx.xxxx", value4 : "TX Tone xxx.x"},

        {key : "Little Gravel RPT", value1 : "RX: xxx.xxxx", value2 : "RX Tone 000.0", value3 : "TX: xxx.xxxx", value4 : "TX Tone xxx.x"}

       ]

};

 

function SetCommandFieldValues(value){

    for(i=0; i<data.items.length; i++){

        if(data.items[i].key === value){

            this.getField("CommandRX").value = data.items[i].value1;

            this.getField("CommandRXTone").value = data.items[i].value2;

            this.getField("CommandTX").value = data.items[i].value3;

            this.getField("CommandTXTone").value = data.items[i].value4;

        }

    }

}

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
New Here ,
Feb 04, 2021 Feb 04, 2021

The above code is within the document javascripts box.

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 ,
Feb 04, 2021 Feb 04, 2021

This defines a variable and a function. Where does you use the function?

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
New Here ,
Feb 04, 2021 Feb 04, 2021

I use a custom keystroke script in the properties of the drop down.

if( event.willCommit ) {
if(event.value == "" || event.value == "Select One") this.resetForm(["CommandRX","CommandRXTone","CommandTX","CommandTXTone"]); else SetCommandFieldValues(event.value);
}

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 ,
Feb 04, 2021 Feb 04, 2021

Does you use the same at all dropdowns?

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
New Here ,
Feb 04, 2021 Feb 04, 2021

Yes, but with different values, keys, and field names. All are unique to a certain set of boxes. And I've named the scripts differently as well.

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 ,
Feb 04, 2021 Feb 04, 2021

Check the console for errors.

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
New Here ,
Feb 04, 2021 Feb 04, 2021

No errors are displaying.

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
New Here ,
Feb 04, 2021 Feb 04, 2021

Is it actually possible to run 3 scripts on the same file or not? All the scripts are exactly the same except the field names, values, and keys. I've just copied and pasted and changed the values/names/keys to what should be displayed with each drop down option.

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 ,
Feb 04, 2021 Feb 04, 2021

You must also use different functions.

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
New Here ,
Feb 04, 2021 Feb 04, 2021

So I can't use this function at the end of each script, but change the names? So it would be SetAirAirFieldValues and SetAirGroundFieldValues for the other two scripts. 

 

function SetCommandFieldValues(value){

    for(i=0; i<data.items.length; i++){

        if(data.items[i].key === value){

            this.getField("CommandRX").value = data.items[i].value1;

            this.getField("CommandRXTone").value = data.items[i].value2;

            this.getField("CommandTX").value = data.items[i].value3;

            this.getField("CommandTXTone").value = data.items[i].value4;

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
LEGEND ,
Feb 04, 2021 Feb 04, 2021

"So I can't use this function at the end of each script, but change the names?" I don't think you're telling us everything about what scripts you have, and where they are. But I can say for sure that there is only one function with a given name. The function is available everywhere, not just in its own box. So if you are duplicating a function and hoping to have three different ones with the same name it won't work. 


There should be no problem with using a different named function for each box. But then, why even have a function?

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 ,
Feb 04, 2021 Feb 04, 2021

You can't use the same name for 3 different functions.

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
New Here ,
Feb 04, 2021 Feb 04, 2021
LATEST

It works now...just had to have different names for the data. So data.items, data1.items, and data2.items.

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