Help with my Javascript to auto populate to two fields

Contributor ,
Aug 14, 2018 Aug 14, 2018

Copy link to clipboard

Copied

Can anyone please help me?  I can't figure out why my javascript isn't working, I am trying to auto populate from a drop down list into two text fields, I am going off the script example in the middle which I got off the internet.  It worked like a charm when I entered the bottom script but I was only auto populating to one text field.  I have ' in front of the digits starting with 0 on the JobStep but I need those.  What am I doing wrong?  PS  I'm very new at this javascript stuff

// Place all prepopulation data into a single data structure

var DeptData = { 1060 Foreman 1:{ JobType: "012DO",

                              JobStep: "’0234" },

                 1031 Foreman 2:{ JobType: "034DO",

                              JobStep: "’0345" },

                 1054 Subforeman:{ JobType: "'056DO",

                              JobStep: "'0756” },

                 1011 Equipment Operator 1:{ JobType: "078DO",

                              JobStep: "'0450” },

                 1015 Equipment Operator 4A :{ JobType: "037DO",

                              JobStep: "0750” },

                 1021 Truck Driver 1:{ JobType: "058DO",

                              JobStep: "'0460” },

                 1022 Truck Driver 2:{ JobType: "094DO",

                              JobStep: "’0260” },

                 1023 Truck Drive 3:{ JobType: "082DO",

                              JobStep: "’0370” },

                 1039 Lead Hand Asphalt:{ JobType: "320DO",

                              JobStep: "1278” },

                 1047 Rough Carpenter:{ JobType: "027DO",

                              JobStep: "0640 },

                 1031 Sweeper Equipment Operator:{ JobType: "068DO",

                              JobStep: "'0115 },

                 1005 Painter Tradesman 1:{ JobType: "036DO",

                              JobStep: "’0020" }};

function SetFieldValuesActingJob1Emp1(cDeptName)

{

  this.getField("TypeJob1Emp1").value = DeptData[cDeptName].JobType;

  this.getField("StepJob1Emp1").value = DeptData[cDeptName].JobStep;

}

This is the scipt I got off the internet as an example:

// Place all prepopulation data into a single data structure

var DeptData = { Accounting:{ contact: "Steala Damuni",

                              email: "accounting@mycomp.com",

                              deptnum: "cmp1234" },

                 Engineering:{ contact: "Frank N. Stien",

                              email: "engineering@mycomp.com",

                              deptnum: "eng1234" },

                 Marketing :{ contact: "Shelly Oughtbuks",

                              email: "marketing@mycomp.com",

                              deptnum: "mkt1234" },

                 ITSupport:{ contact: "Goah  Wei",

                              email: "it@mycomp.com",

                              deptnum: "its1234" }};

function SetFieldValues(cDeptName)

{

  this.getField("DeptContact").value = DeptData[cDeptName].contact;

  this.getField("DeptEmail").value = DeptData[cDeptName].email;

  this.getField("DeptNumber").value = DeptData[cDeptName].deptnum;

}

// Place all prepopulation data into a single data structure

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

                 Temp:{ Type: "2" },

                 Acting :{ Type: "11" },

                 Auxiliary:{ Type: "3" },

                 COT:{ Type: "263" },

                 POT:{ Type: "266" },

                 Vacation:{ Type: "300" },

                 Sick:{ Type: "400" }};

function SetFieldValuesTypeJob1Emp1(cDeptName)

{

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

}

This is the script I entered that works great

// Place all prepopulation data into a single data structure

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

                 Temp:{ Type: "3" },

                 Acting :{ Type: "12" },

                 Auxiliary:{ Type: "4" },

                 COT:{ Type: "267" },

                 POT:{ Type: "256" },

                 Vacation:{ Type: "902" },

                 Sick:{ Type: "430" }};

function SetFieldValuesTypeJob1Emp1(cDeptName)

{

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

}

TOPICS
Acrobat SDK and JavaScript

Views

161

Likes

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

correct answers 1 Correct Answer

Adobe Community Professional , Aug 14, 2018 Aug 14, 2018
Change the IDs like this:var DeptData = { "1060 Foreman 1":{ JobType: "012DO",                              JobStep: "’0234" },                 "1031 Foreman 2":{ JobType: "034DO",                              JobStep: "’0345" },   ...

Likes

Translate

Translate
Adobe Community Professional ,
Aug 14, 2018 Aug 14, 2018

Copy link to clipboard

Copied

Change the IDs like this:

var DeptData = { "1060 Foreman 1":{ JobType: "012DO",

                              JobStep: "’0234" },

                 "1031 Foreman 2":{ JobType: "034DO",

                              JobStep: "’0345" },

   ...

Likes

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
Contributor ,
Aug 15, 2018 Aug 15, 2018

Copy link to clipboard

Copied

I tried putting in the quotes like you've shown which I thought for sure would work but it won't auto populate. If I don't enter the quotes 1060 and 1 next to Foreman goes red and so on goes red when I enter the script in Notebook ++.  Although the bottom example shows one that does work without the quotes.  Please help me.

if( event.willCommit )
{
   if(event.value == " ")
     this.resetForm(["TypeJob1Emp1","StepJob1Emp1"]);
   else
     SetFieldValues(event.value);
}

// Place all prepopulation data into a single data structure
var ActingData = {"1060 Foreman 1":{JobType: "02DO",
        JobStep: "'0501"},
                 "1031 Foreman 2":{JobType: "084DO",  
        JobStep: "'0281"},
                 "1054 Subforeman":{JobType: "049DO",  
        JobStep: "'0460"},
                 "1011 Equipment Operator 1":{JobType: "069DO",  
        JobStep: "0590"},
                 "1015 Equipment Operator 4A":{JobType: "034DO",  
        JobStep: "'0690"},
                 "1021 Truck Driver 1":{JobType: "019DO",  
        JobStep: "'0200"},
                 "1022 Truck Driver 2":{JobType: "068DO",  
        JobStep: "'0630"},
                 "1023 Truck Driver 3":{JobType: "039DO",  
        JobStep: "0970"},
                 "1039 Lead Hand Asphalt":{JobType: "893DO",  
        JobStep: "1699"},
                 "1047 Rough Carpenter":{JobType: "035DO",  
        JobStep: "'0680"},
                 "1013 Sweeper Equipment Operator":{JobType: "034DO",
        JobStep: "'0910"},
                 "1005 Painter Tradesman 1":{JobType: "083DO",
        JobStep: "'0760"}};
function SetFieldValuesActingJob1Emp1(cActingName)
{
  this.getField("TypeJob1Emp1").value = ActingData[cActingName].JobType;
  this.getField("StepJob1Emp1").value = ActingData[cActingName].JobStep;
}

if( event.willCommit )
{
   if(event.value == " ")
     this.resetForm(["PayType Job1Emp1"]);
   else
     SetFieldValuesTypeJob1Emp1(event.value);
}

// Place all prepopulation data into a single data structure
var PDBAData = { Regular:{ Type: "9" },
                 Temp:{ Type: "17" },
                 Acting :{ Type: "19" },
                 Auxiliary:{ Type: "9" },
     COT:{ Type: "254" },
     POT:{ Type: "696" },
     Vacation:{ Type: "902" },
     Sick:{ Type: "836" }};
function SetFieldValuesTypeJob1Emp1(cPDBAName)
{
  this.getField("PayType Job1Emp1").value = PDBAData[cPDBAName].Type;
}

Likes

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
Contributor ,
Aug 15, 2018 Aug 15, 2018

Copy link to clipboard

Copied

LATEST

Oh my gosh, I figured out what I was doing wrong and it works beautifully, I can't thank you enough Bernd, thank you thank you!!!

Likes

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