I have these two functions which both work, but I would like to cut it down to one if possible. They populate dropdown lists on two forms. Any thoughts on how to change this to one function?:
// Begin populateSupportSelect
function populateSupportSelect(x, y) {
//get the domain value
var domain = app.supportLayer.getDomain(x);
//get the html select by ID
var select = document.getElementById(y);
//clear the current options in select
for (var option in select) {
select.remove(option);
}
var opt = document.createElement('option');
opt.innerHTML = "";
select.appendChild(opt);
//loop through the domain value to fill the drop down
for (var i = 0; i < domain.codedValues.length; i++) {
console.log(domain.codedValues.name);
; var opt = document.createElement('option');
opt.innerHTML = domain.codedValues.name;
opt.value = domain.codedValues.name;
select.appendChild(opt);
}
}
// End populateSupportSelect
// Begin populateSelect
function populateSelect(x, y) {
//get the domain value
var domain = app.signLayer.getDomain(x);
//get the html select by ID
var select = document.getElementById(y);
//clear the current options in select
for (var option in select) {
select.remove(option);
}
var opt = document.createElement('option');
opt.innerHTML = "";
select.appendChild(opt);
//loop through the domain value to fill the drop down
for (var i = 0; i < domain.codedValues.length; i++) {
console.log(domain.codedValues.name);
; var opt = document.createElement('option');
opt.innerHTML = domain.codedValues.name;
opt.value = domain.codedValues.name;
select.appendChild(opt);
}
}
// End populateSelectHere is how I populate the dropdown lists:
/* Enter your domain item and then the element to populate */
populateSelect("BACKING", "backing");
populateSelect("VISIBILITY", "visibility");
populateSelect("CONDITION_", "condition");
populateSelect("COLOR1", "color1");
populateSelect("DELINEATOR", "delineator");
populateSelect("ILLUM", "illum");
populateSelect("ATTACHTYPE", "attachType");
populateSelect("ATTACHLOC", "attachLoc");
populateSelect("SITEOBS", "siteObs");
populateSelect("SIGNSHAPE", "signShape");
populateSelect("COLOR2", "color2");
populateSelect("MUTCD", "mutcd");
/* Show supports form */
} else if (severity === "1") {
app.attributesModal.modal("show");
/* Enter your domain item and then the element to populate */
populateSupportSelect("TYPE", "type");
populateSupportSelect("SIZE_", "size");
populateSupportSelect("MATERIAL", "material");
populateSupportSelect("BASE", "base");
populateSupportSelect("RATING", "rating");
}