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

Autopopulate question

Engaged ,
Aug 11, 2018 Aug 11, 2018

Copy link to clipboard

Copied

I have a document with 48 drop down lists (same info on each).  The dropdown lists are each named individually (PayTypeDesc Job1Emp1, PayTypeDesc Job1 Emp2, PayType Job1Emp3 etc.)  I would like each dropdown list to autopopulate to a separate table below where I named each text field  PayType Job1Emp1, PayType Job1Emp2, PayType Job1 Emp3 etc.   For example, dropdown list named PayType Job1Emp1 will autopopulate to field named PayType Job1Emp1, then dropdown list named PayType Job1Emp2 will autopoulate to Job1Emp2 etc.

When I entered the following script it worked on the first line but it didn’t work on the second one and I have another 47 to go, I just can’t seem to figure out how to make each one do it’s own individual purpose.  Do I have to give each one a different Script Name and if so what do I name it?

I followed what is on this website which is how I got the script below https://acrobatusers.com/tutorials/change_another_field

Under dropdown Properties I select ‘Commit Selected Value Immediately’ then I custom enter under format on the Custom Keystroke Event I enter the following code:

if( event.willCommit )

{

   if(event.value == " ")

     this.resetForm(["PayType Job1Emp1"]);

   else

     SetFieldValues(event.value);

}

Under document javascripts I give the Script Name ‘SetFieldValues” then enter:

// Place all prepopulation data into a single data structure

var DeptData = { Regular:{ PayType: "1" },

                 Temp:{ PayType: "2" },

                 Acting :{ PayType: "11" },

                 Auxiliary:{ PayType: "3" },

                 COT:{ PayType: "263" },

                 POT:{ PayType: "266" },

                 Vacation:{ PayType: "300" },

                 Sick:{PayType: "400" }};

function SetFieldValues(cDeptName)

{

  this.getField("PayType Job1Emp1").value = DeptData[cDeptName].PayType;

TOPICS
Acrobat SDK and JavaScript

Views

248

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
LEGEND ,
Aug 11, 2018 Aug 11, 2018

Copy link to clipboard

Copied

You could modify the script to pass the relevant field name, something like:

// Keystroke script

if (event.willCommit ) {

    sFN = "PayType Job1Emp1";  // Change to correct field name in each Keystroke script

    if (event.value == " ") {

        this.resetForm([sFN]);

    } else {

        SetFieldValues(event.value, sFN);

    }

}

And change the function to:

function SetFieldValues(cDeptName, sFieldName) {

    this.getField(sFieldName).value = DeptData[cDeptName].PayType;

}

With a more consistent field naming convention you wouldn't have to hardcode the field names in the Keystroke scripts, as they could be determined from the name of the dropdown, which the Keystroke script has access to in event.target.name.

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
Engaged ,
Aug 11, 2018 Aug 11, 2018

Copy link to clipboard

Copied

LATEST

Thanks for the reply George! I'll try that. I actually just now figured it out a different way but yours might be easier.

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