Populating multiline text field from combo box using nested if - else if
I have Acrobat Pro DC with a combo/dropdown box ("Regulation) which is populated by another parent dropdown box. When I change the value on "Regulation" box, i.e.: select a Regulation), it populates yet another combo box ("RegSections") with the appropriate sections for the particular regulation selected such as: 2, 2(1), 2(2) etc.. See image of fields below.

That all works great as they're using the "Case" command. BUT when I choose a section from the last box, it's supposed to populate a text box with the appropriate regulatory description for the section selected. It is a good 1225 lines long and works fine on the "RegSections" Blur event but that means an officer would need to click outside the box before the proper text shows up in the text box ("sfd_reg"). Currently the js is simply a nested if/else-if setup.
What I've been trying to do is make it work on the "RegSections" Custom Keystroke event. So I added a if(!event.willcommit){ to the top of the script and the closing "}" right at the end so it encapsulates the entire script. However, this approach doesn't seem to be working as effectively as the Blur event because when I select a different section, the text field is not updated until I perform the selection a second time. (???) I hope this all makes sense.
Below are two versions of a portion of the script that I've chopped up into small versions (didn't see an option here for inserting a code block):
1) In the BLUR EVENT (recap: works but have to click outside box, no immediate update to text field "sfd_reg":
//Setup form variables
var reg = this.getField("Regulation").value;
var rsec = this.getField("RegSections");
var rsf = this.getField("sfd_reg");
if (reg == "Antarctic Environmental Protection Regulations (AEPR)") {
if (rsec.value == "12(1)(a)") {
rsf.value = "Failure to ensure that specified persons receive specified training";
} else if (rsec.value == "12(1)(b)") {
rsf.value = "Failure to inform specified persons of permit and Regulations requirements";
} else if (rsec.value == "12(1)(c)") {
rsf.value = "Failure to provide specified report within specified period";
}
} else if (reg == "Concentration of Phosphorous in Certain Cleaning Products Regulations (CPCCPR)") {
if (rsec.value == "8") {
rsf.value = "Failure to maintain record containing information as specified";
}
} else if (reg == "Export and Import of Hazardous Waste and Hazardous Recyclable Materials Regulations (EIHWHRMR)") {
if (rsec.value == "3(a)") {
rsf.value = "Releasing, allowing or causing release of halocarbon from specified system, container or device";
} else if (rsec.value == "3(b)") {
rsf.value = "Releasing, allowing or causing release of halocarbon from specified system, container or device";
}
} else {
app.alert("No Regulation selected", 3, 0, "Select a Regulation");
rsf.value = "Choose an Act and Section";
}
2) In the CUSTOM KEYSTROKE (recap: kind've works but have to make selection twice before "sfd_reg" is populated with desired text (no one would like that and it's not intuitive):
//Setup form variables
var reg = this.getField("Regulation").value;
var rsec = this.getField("RegSections");
var rsf = this.getField("sfd_reg");
if(!event.willCommit)
{
if (reg == "Antarctic Environmental Protection Regulations (AEPR)") {
if (rsec.value == "12(1)(a)") {
rsf.value = "Failure to ensure that specified persons receive specified training";
} else if (rsec.value == "12(1)(b)") {
rsf.value = "Failure to inform specified persons of permit and Regulations requirements";
} else if (rsec.value == "12(1)(c)") {
rsf.value = "Failure to provide specified report within specified period";
}
} else if (reg == "Concentration of Phosphorous in Certain Cleaning Products Regulations (CPCCPR)") {
if (rsec.value == "8") {
rsf.value = "Failure to maintain record containing information as specified";
}
} else if (reg == "Export and Import of Hazardous Waste and Hazardous Recyclable Materials Regulations (EIHWHRMR)") {
if (rsec.value == "3(a)") {
rsf.value = "Releasing, allowing or causing release of halocarbon from specified system, container or device";
} else if (rsec.value == "3(b)") {
rsf.value = "Releasing, allowing or causing release of halocarbon from specified system, container or device";
}
} else {
app.alert("No Regulation selected", 3, 0, "Select a Regulation");
rsf.value = "Choose an Act and Section";
}
}
HELP. Thanks!!!!
