I have a form with a multiple select inside a bootstrap modal:
<label>Product:</label>
<select name="product[]" multiple="multiple" id="product">
<option value="1">Product 1</option>
<option value="2">Product 2</option>
<option value="3">Product 3</option>
<option value="4">Product 4</option>
<option value="5">Product 5</option>
<option value="6">Product 6</option>
</select><br />
I'll save my data from this form to a single field in a Mysql database like 1, 4, 6 (I used implode to do this)
Now when I call a modal to edit my form, I want to see the multiple select with the values 1, 4 and 6 selected.
Is there a way to achieve this?
EDIT:
Thanks for the quick answers! All were useful, but when I'm using a lot of modals, maybe it's better to call them using javascript and fill the fields in the form like:
HTML:
<a href='#afvalstoffen-edit' class='afvalstoffen-edit' data-toggle='modal' data-id='$id' data-product='$product'......
JAVASCRIPT:
$(document).on("click", ".afvalstoffen-edit", function () {
var data_id= $(this).data('id');
var product= $(this).data('product');.....
And then fill the form in the modal like:
......
$(".modal-body #data_id").val( data_id);
$(".modal-body #product").val( product);
$('#afvalstoffen-edit').modal('show');
});
Is there also a way to get the values of the multiple select selected this way?
SOLUTION:
var product = "product1, product2, product3";
var product_array = product.split(", ");
$(".modal-body #product").val( product_array );
DEMO: