Skip to main content
Participant
January 18, 2017
Answered

PDF JS Multiple Dropdowns, Multiple Function SetfieldValues

  • January 18, 2017
  • 1 reply
  • 1181 views

Hi all

I have a quick query that hopefully someone can clear up with me. I have been creating a PDF document with dropdowns, and followed this guide which worked perfectly for me when populating other fields. My problem started when I wanted to add a second drop down, this dropdown contains the same content and needs to populate different fields in the same way as the first. The way I wrote the function for the second drop down is as follows. I know this is wrong because the functions have the same name but I do not understand scripting enough on how to name them differently, currently selecting a option from Dropdown1 will change the fields Duration2, Funding2 and Cont2.

Dropdown 1 Keystroke Script

if( event.willCommit )

{

   if(event.value == " ")

     this.resetForm(["Duration1","Funding1","Cont1"]);

   else

     SetFieldValues(event.value);

}

Dropdown 2 Keystroke Script

if( event.willCommit )

{

   if(event.value == " ")

     this.resetForm(["Duration2","Funding2","Cont2"]);

   else

     SetFieldValues(event.value);

}

Document Script

var

Dropdown1Data = {Product A:{ Duration1: "6 Months",

                              Funding1: "£100",

                              Cont1: "£10" },

                              Product B :{ Duration1: "12 Months",

                              Funding1: "£200",

                              Cont1: "£20" },;

                

Dropdown2Data = {Product A:{ Duration2: "6 Months",

                              Funding2: "£100",

                              Cont2: "£10" },

                              Product B :{ Duration2: "12 Months",

                              Funding2: "£200",

                              Cont2: "£20" },;

function SetFieldValues(cDropdown1)

{

  this.getField("Duration1").value = Dropdown1Data[cDropdown1].Duration1;

  this.getField("Funding1").value = Dropdown1Data[cDropdown1].Funding1;

  this.getField("Cont1").value = Dropdown1Data[cDropdown1].Cont1;

}

function SetFieldValues(cDropdown2)

{

  this.getField("Duration2").value = Dropdown2Data[cDropdown2].Duration2;

  this.getField("Funding2").value = Dropdown2Data[cDropdown2].Funding2;

  this.getField("Cont2").value = Dropdown2Data[cDropdown2].Cont2;

}

If you could help me work this one out it would be great, I have found other links that discuss the same issue, although I have not been smart enough to understand what to do now that I have the answer.

Thanks

Steve

This topic has been closed for replies.
Correct answer try67

Hi Try67

Here you go (Dropbox link),

EDIT: When I set the function names to SetFieldValues1 and SetFieldValues2 I noticed that the dropdowns will not work at all outside of Acrobat (X pro).

var

Dropdown1Data = {ProductA:{ Duration1: "6 Months",

                              Funding1: "£100",

                              Cont1: "£10" },

                 ProductB :{ Duration1: "12 Months",

                              Funding1: "£200",

                              Cont1: "£20" }};

Dropdown2Data = {ProductA:{ Duration2: "6 Months",

                              Funding2: "£100",

                              Cont2: "£10" },

                 ProductB :{ Duration2: "12 Months",

                              Funding2: "£200",

                              Cont2: "£20" }};

  

function SetFieldValues(cDropdown1)

{

  this.getField("Duration1").value = Dropdown1Data[cDropdown1].Duration1;

  this.getField("Funding1").value = Dropdown1Data[cDropdown1].Funding1;

  this.getField("Cont1").value = Dropdown1Data[cDropdown1].Cont1;

}

function SetFieldValues(cDropdown2)

{

  this.getField("Duration2").value = Dropdown2Data[cDropdown2].Duration2;

  this.getField("Funding2").value = Dropdown2Data[cDropdown2].Funding2;

  this.getField("Cont2").value = Dropdown2Data[cDropdown2].Cont2;

}

Dropdown1 Keyscript

if( event.willCommit )

{

   if(event.value == " ")

     this.resetForm(["Duration1","Funding1","Cont1"]);

   else

     SetFieldValues(event.value);

}

Dropdown2 Keyscript

if( event.willCommit )

{

   if(event.value == " ")

     this.resetForm(["Duration2","Funding2","Cont2"]);

   else

     SetFieldValues(event.value);

}


You need to change not just the names of the functions in their

definitions, but also in the call to them (under the Keystroke events)...

On Thu, Jan 19, 2017 at 10:46 AM, SteveK1982 <forums_noreply@adobe.com>

1 reply

try67
Community Expert
Community Expert
January 18, 2017

You just need to rename the SetFieldValues functions, so each one has a

unique name, like SetFieldValues1, SetFieldValues2...

On Wed, Jan 18, 2017 at 6:45 PM, SteveK1982 <forums_noreply@adobe.com>

Participant
January 18, 2017

Hi try67

I had given that a go, although it didn't seem to resolve the issue.

Steve

try67
Community Expert
Community Expert
January 18, 2017

Post your new code, or better yet share the file with us, please.