I've been having some trouble adding options to a chart.js <select>
from an array of <option>
s. I used the same rough procedure all the time, so I'm not sure why it's failing me now...
What I'm doing:
- I have several
<select>
s which look more or less like this:
<select id='soilname' data-placeholder='Type here' multiple class='chosen-select'>
<option value=''></option>
</select>
- A sequence of steps that gets me to an array of
<option>
s. This array is calledoptnames
. - I iterate through the array, adding it to several
<select>
s:
for(var i=0; i < optnames.length; i++)
{
document.getElementById("soilname").appendChild(optnames[i]);
document.getElementById("soilyearname").appendChild(optnames[i]);
document.getElementById("albedoname").appendChild(optnames[i]);
document.getElementById("dcname").appendChild(optnames[i]);
document.getElementById("acname").appendChild(optnames[i]);
}
- Some distance later, I activate chosen.js:
jQuery(".chosen-select").chosen({
width: "400px"
});
I made sure to include all relevant files and plugins in <script>
tags. I've also console.log()
ed optnames
to make sure the array is what I expect it to be. The several other pages on this very topic propose good solutions -- none work. Any thoughts as to what the error could be?
EDIT: some screenshots: