JQuery Bootstrap Multiselect plugin - Set a value as selected in the multiselect dropdown
//Do it simple
var data="1,2,3,4";
//Make an array
var dataarray=data.split(",");
// Set the value
$("#multiselectbox").val(dataarray);
// Then refresh
$("#multiselectbox").multiselect("refresh");
Thank you all for your answers.
Taking all of your answers as a guideline, I resolved the problem with the below code:
var valArr = [101,102];
i = 0, size = valArr.length;
for(i; i < size; i++){
$("#data").multiselect("widget").find(":checkbox[value='"+valArr[i]+"']").attr("checked","checked");
$("#data option[value='" + valArr[i] + "']").attr("selected", 1);
$("#data").multiselect("refresh");
}
Thanks once again for all your support.
It's supposed to be as simple as this:
<select id='multipleSelect' multiple='multiple'>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<script type='text/javascript'>
$('#multipleSelect').val(['1', '2']);
</script>
Check my Fiddle: https://jsfiddle.net/luthrayatin/jaLygLzo/