Skip to main content
Participating Frequently
August 25, 2020
Question

Multiple Combo boxes using the same set of predetermined data.

  • August 25, 2020
  • 1 reply
  • 978 views

My expertise in Java is -1, so complete newbie here. 

I turned to this common link to learn about combo boxes: https://acrobatusers.com/tutorials/change_another_field/ and am slowly getting this to work on its own.  Now my question, is it possible, using this code from the above link: 


// 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;

}

And repeat it within the same JavaScript? I figured out how to set the combo box to give me the values I want, but not to a separate combo box giving me different values. Example:

Combobox A (DeptData) is given a selection and autopopulates gives me output for Engineering
Combobox B (DeptData1) pulls from the same group of prefilled options and gives me output for Accounting.

Using two combo boxes, I can get two sets of data. I hope I'm making sense.

Otherwise, I'm making 150+ scripts, one for each possible selection with the same group of outputs.

Thank you,
Lahrs

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
August 26, 2020

Yes, it sure is. You can either do it by supplying the names of the fields as parameters to the SetFieldValues function, or by duplicating it and renaming it for each set of fields. The former is a better option, of course, as its more generic. The code would then need to be placed as a doc-level script, and you just call it from each field's Validation or Format event with the correct function name or parameters.

Participating Frequently
August 26, 2020

I'm being dense and not getting it. Like I said, I'm brand new to this and trying tutorials. I've finished the combo box one above, but need to have duplicate with different results:

All I've done is copy and pasted the fields and then renamed then added a 1 in the second field names. Otherwise they would just show up identical no matter what I did.

// 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 DeptData1 = { 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(aDeptName)
{
  this.getField("DeptContact1").value = DeptData1[aDeptName].contact;
  this.getField("DeptEmail1").value = DeptData1[aDeptName].email;
  this.getField("DeptNumber1").value = DeptData1[aDeptName].deptnum;
}

I then did the same with the DeptData1 and the getField("DeptContact1") and so forth. Now all that happens is the left and right combo box controls just the right data boxes. I wish I was able to take a javascript class but there are none where I live, so it is just books, demos and asking questions here.

try67
Community Expert
Community Expert
August 26, 2020

- Do not duplicate the data model. The entire point of doing it is to have only one source of the data.

- Each function needs to have a unique name. Rename the second function to SetFieldValues1, for example, and then call it from your second field, instead of SetFieldValues, which should be called from the first one.