Today I try to make a dynamic dropdownlist using jQuery. I only provide one select list on the page at started. After usser selecting a option, if the selected category has sub categories, one new select list will be added next to the original select list by jQuery.
But I don't know how to implement my idea. How to add a select list and add options to the select list, finally add it to page using jQuery.
My codes are below:
$.getJSON(
'/Work/Content/Categories/' + currentValue,
'{Id:Name}',
function (data) {
if (data.length > 0) {
$current.append('<select></select>');
$selectList = $('fieldset > select:last');
$.each(data, function (index, value) {
var option = new Option(value.Id, value.Name);
if ($.browser.msie)
$selectList.add(option);
else
$selectList.add(option, null);
});
}
}
);
Thanks every body.