I am trying to make a dynamic select dropdown, I tried writing the code in javascript and jquery both but can't append the options in the dropdown. When I tried seeing what is stored then the Html select code along with all the options is shown. What should I add or change in it so the options are stored in the correct position?
lines=["B","C","D","E","F","G"];
$(document).ready(function(){
$("#select1").multiselect({
placeholder: 'Features'
});
});
// var selectFir = document.getElementById("select1");
// for (var i = 0; i < firstLine.length; i++) {
// var x = document.createElement("OPTION"),
// txt = document.createTextNode(firstLine[i]);
// x.appendChild(txt);
// x.setAttribute("value", firstLine[i]);
// selectFir.appendChild(x);
// selectFir.insertBefore(x, selectFir.lastChild);
// }console.log(selectFir);
firstLine = lines[0];
// Calls function to generate drop downs using options above
for(var i=0; i< firstLine.length;i++)
{
//creates option tag
jQuery('<option/>', {
value: firstLine[i],
html: firstLine[i]
}).appendTo('#select1');
}
jQuery('#select1').multiselect('refresh');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/multiselect/2.2.9/js/multiselect.min.js"></script>
<select multiple id="select1">
<option value="A">A</option>
</select>