1

I am using two multiselect dropdown. second multiselect option is depends on first multiselect values.

I am trying to fill the second multiselect (#field_zone) option using ajax call when first dropdown (#participation_channels) option is select or deselect. I'm trying to populate second multiselect dropdown(#field_zone) but second dropdown is not populate

plugin used

 $(document).ready(function () {
    $('#participation_channels').multiselect({
        onChange: function (option, checked) {
            var channels = $('#participation_channels').val();
            $.ajax({
                url: "url",
                data: {channels: channels},
                type: "POST",
                dataType:'json',
                cache: false,
                success: function (data) {
                    $.each(data, function(i, zone) {
                        $("#field_zone").append('<option value="' + zone.zone + '">' + zone.zone + '</option>');
                    });
                    $("#field_zone").attr('multiple', 'multiple'); 
                   $("#field_zone").multiselect(); 
                }
            });
        }
    });
    $('#field_zone').multiselect();
}); 

1 Answer 1

2

You need to force the multiselect to regenerate all options from the original select element. So, after creating the new options for the select (inside the success callback) you should change:

$("#field_zone").multiselect();

to:

$("#field_zone").multiselect('rebuild');

so the multiselect will be rebuilt based on the updated options.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.