I have problem to set multiple values in the multiple select input. For example I need to set value 2,3 (Ketchup, Relish) in the multi-select input when I've clicked the Show Selected Option button, then the value will show in the input field.
Below is I want the expected result:
Below is my coding that I've tried, I've used this method $('.selectpicker').val(value); but it cannot work.
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.1/css/bootstrap-select.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.bundle.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.1/js/bootstrap-select.min.js"></script>
<select class="selectpicker" value="" multiple data-live-search="true">
<option value="1">Mustard</option>
<option value="2">Ketchup</option>
<option value="3">Relish</option>
</select>
<button type="button" class="btn btn-sm btn-primary create-permission" id="btn_save" value="Save" onclick="sendFunc()">Show Selected Option</button>
<script>
$('select').selectpicker();
function sendFunc(){
var value = "2,3";
$('.selectpicker').val(value);
}
</script>
Hope someone can guide me on how to solve this problem. Thanks.
