Dependant Dropdown
Hi
I have tried to create a dependant dropdown in a form using a code I copied from another link.
It appears to be working at first, users can select an item from the first dropdown and this then populates the options in the second dropdown and these can also be selected. However, when the form is saved and is re-opened the second dropdown defaults to "Please Select". I have copied the code below, can anyone tell me what I've done wrong?
Thank you
Yvonne
/*
LICENSE:
acrojs_dependentList.js by Joel Geraci is licensed under a Creative Commons Attribution 4.0 International License.
https://creativecommons.org/licenses/by/4.0/
You are free to:
Share — copy and redistribute the material in any medium or format
Adapt — remix, transform, and build upon the material for any purpose, even commercially.
Setup:
For list boxes: Add this script to the "selection change" script of the master list box.
For combo boxes: Add this script to the "custom format" script of the dropdown box.
IMPORTANT!
Edit the following line to identify the field name of the dependent list box then edit the properties of the dependentListValues JSON object. Property names should correspond to the export values of the list items.
*/
var dependentListBoxFieldName = "dependentDropdown";
var dependentListValues =
{
"In paid employment": [
["Please Select", "Please Select"],
["In paid employment for 16 hours or more per week", "In paid employment for 16 hours or more per week"],
["In paid employment for less than 16 hours per week", "In paid employment for less than 16 hours per week"],
["Self-employed for 16 hours or more per week", "Self-employed for 16 hours or more per week"],["Self-employed for less than 16 hours per week","Self-employed for less than 16 hours per week"]
],
"Not in paid employment": [
["Please Select", "Please Select"],
["Not in paid employment, looking for work and available to start work", "Not in paid employment, looking for work and available to start work"],
["Not in paid employment, not looking for work and / or not available to start (including retired)", "Not in paid employment, not looking for work and / or not available to start (including retired)"]
],
"Voluntary Gap Year": [
["Please Select", "Please Select"],
["Voluntary Work", "Voluntary Work"],
["Gap Year before starting HE", "Gap Year before starting HE"]
],
"Education": [
["Please Select", "Please Select"],
["Traineeship", "Traineeship"],
["Apprenticeship", "Apprenticeship"],
["Supported Internship", "Supported Internship"],
["Other FE (Full Time)", "Other FE (Full Time)"],
["Other FE (Part Time)", "Other FE (Part Time)"],
["HE", "HE"]
],
"Other": [
["Please Select", "Please Select"],
["Other outcome not listed", "Other outcome not listed"],
["Unable to Contact Learner", "Unable to Contact Learner"],
["Not Known", "Not Known"]
]
};
/*
You probably don't need to change anything from here down
*/
if ((event.target.type == "combobox" && event.name == "Format") || (event.target.type == "listbox" && event.name == "Keystroke")) {
if (event.target.type == "combobox") {
if (dependentListValues.hasOwnProperty(event.target.value)) {
this.getField(dependentListBoxFieldName).setItems(dependentListValues[event.target.value]);
}
else {
this.getField(dependentListBoxFieldName).clearItems();
}
}
if (event.target.type == "listbox" && dependentListValues.hasOwnProperty(event.changeEx)) {
this.getField(dependentListBoxFieldName).setItems(dependentListValues[event.changeEx]);
}
}
else {
app.alert("This script was not intended for this field type or event.");
}
