Forum Moderators: open
I'm stuck with a slight problem that I hope someone can help me with. I have a very large array (short version below) that I'm using to populate a series of dropdowns with. The full thing is working exactly as I want, but the way it's set up, the first set is showing the same item multiple times. So in the example below, I see "Red" 4 times.
Is there any way to filter this out in my loop so each unique "groupid" only shows up once? I'm currently using jQuery where I can, so I'm open to any solution that could provide as well.
$(document).ready(function() {
var units = [
{groupid:"Red", zone:"Section 1"},
{groupid:"Red", zone:"Section 2"},
{groupid:"Red", zone:"Section 3"},
{groupid:"Red", zone:"Section 4"},
{groupid:"Blue", zone:"Section 2"},
{groupid:"Blue", zone:"Section 4"},
{groupid:"Blue", zone:"Section 6"},
{groupid:"Green", zone:"Section 5"},
{groupid:"Green", zone:"Section 6"}
]
for (var unitlist = 0; unitlist< units.length; unitlist++) {
buildList(document.unit_list.groups, units[unitlist].groupid, units[unitlists].groupid, "");
}
});
function buildList(selectbox, value, text ) {
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
selectbox.options.add(optn);
}
Thanks in advance for any help/advice!