Iftakharul Alam
Iftakharul Alam

Reputation: 3321

Semantic UI dynamic dropdown reinitialize issue

I use semantic UI dropdown plugin. active the plugin on load by

$(function () {
   $('select.dropdown').dropdown();
});

in my code there is two dropdown one's date is dependen on other. on change first dropdown I populate other's value.

$('.city').on('change', function () {
    var id = $(this).val();
    if (id != '') {
        $.get('ajax/town/' + id).done(function (result) {
            var div = '';
            $.each(result, function (i, e) {
                div += '<option value="' + e.id + '">' + e.town + '</option>';
            });
            $('.town').html(div);
            $('select.dropdown.town').dropdown('refresh');
        });
    }
});

But the dropdown doesnot reinitialize, but show a list in a div. How to solve this issue.

Upvotes: 0

Views: 1358

Answers (1)

Iftakharul Alam
Iftakharul Alam

Reputation: 3321

The problem solved. by changing...

$('.town').html(div);
$('select.dropdown.town').dropdown('refresh');

to

$('.town select').html(div).dropdown();

Upvotes: 1

Related Questions