Using a previously answered SO question as a reference, I created a function that populates a dropdown list in my HTML doc from an existing javascript array.
Here's the HTML:
<fieldset>
<legend>Choose action</legend>
<p>Choose your action and click next</p><br />
<select id="trigger"></select>
</fieldset>
Here's the Javascript:
var guns =
[
["Smith and Wesson 500", "Revolver", "Full Frame", 50, "sada"], //model, type, frame, cal, trigger
["Glock 19", "Semi", "Compact", 9, "striker"],
["Smith and Wesson M and P Shield 9", "Semi", "Compact", 9, "striker"],
["Ruger Alaskan", "Revolver", "Full Frame", 44, "dao"],
["Ruger SR9", "Semi", "Compact", 9, "striker"],
["Desert Eagle", "Semi", "Full Frame", 50, "sada"],
["Smith and Wesson M and P Shield 40", "Semi", "Compact", 40, "striker"]
]
var triggerDropdown = function(){
var sel = document.getElementById('trigger');
for (var i = 0; i < guns.length; i++) {
var opt = document.createElement('option');
opt.innerHTML = guns[i][4];
opt.value = guns[i][4];
sel.appendChild(opt);
}
};
My challenge:
Populate trigger
without duplicates. Also, the solution must not require me to permanently change guns
(I found a few other helpful SO posts, but most of them involve first removing duplicates from the array...in this case, I don't have the option).
Thank you!