So, I am trying to append the options to the HTML5 select using jquery but it doesnt work for some reason. Following is my code:
for (var i = 0; i < itemsList.length; i++) {
WL.Logger.debug(itemsList[i]);
var elem = $("<option/>").val(itmesList[i]).text(itemsList[i]);
$('#itemsList').append(elem);
}
Here itemsList is an array of items whose value i want to append to the select dropdown box whose id is itemsList as well. here is the html code:
<div id="wrapper">
<label for="itmesList">Select item: </label>
<select id="itmesList"></select>
<div id="info"></div>
</div>
Any ideas what I am doing wrong here? Thanks!
Yes.
<select id="itmesList">
$('#itemsList')
itmesList != itemsList
Edit
Also here.
itmesList[i]
When you see it.
HTML:
<div id="wrapper">
<label for="itmesList">Select item: </label>
<select id="selectItem"></select>
<div id="info"></div>
</div>
JQuery:
var itemsList = ['a', 'b', 'c'];
var options = "";
for (var i = 0; i < itemsList.length; i++) {
alert(itemsList.length);
options += '<option value= "' + itemsList[i] + '">' + itemsList[i] + '</option>';
}
$('#selectItem').html(options);
DEMO: http://jsfiddle.net/Simplybj/WKfak/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With