I am using bootstrap-multiselect and need to submit form with selected options.
However on form submit, url gets like this ....&sites=1&sites=2&sites=3
while I need it to be ...&sites=1,2,3
Here is my code:
<select id="sites" name="sites" class="form-control" multiple="multiple">
<option value="1">Site 1</option>
<option value="2">Site 2</option>
<option value="3">Site 3</option>
</select>
JS:
$('button[type=submit]').click(function () {
var text = $('#sites').val()
//I have the list in `text` as 1,2,3 which need to in url
//do the rest and continue submit
How can I POST these selected values in url (i.e url/sites=1,2,3
instead of url/sites=1&sites=2&sites=3
)
Thanks for any help!
You may rename select to sites[]
<select id="sites" name="sites[]" class="form-control" multiple="multiple">
<option value="1">Site 1</option>
<option value="2">Site 2</option>
<option value="3">Site 3</option>
</select>
This is will be send to server by submit without any js one variable sites as array with multi selected options.