str - an array from the database
$('#dropdown').multiselect({includeSelectAllOption: true,}); $("#dropdown").multiselect('deselectAll', false);
initialize and reset first perform decimation.
for(i=0; i<= str.length; i++){ $("#dropdown").find("option[value='"+ $.trim(str[i])+"']").prop("selected", true); $("#dropdown").find("option[value='"+ $.trim(str[i])+"']").attr("selected", "selected"); } $("#dropdown").multiselect("refresh");
this code will pre-select the values.
Also, if you want to reset, the dropdown menu below is the code
$('#dropdown').multiselect({includeSelectAllOption: true,}); $("#dropdown").multiselect('deselectAll', false); $("#dropdown").multiselect("refresh");
Do not forget to update. This code is checked and verified. works for me.
source share