Reputation: 1
I have a select option(drop down)
on my hmtl. I want to post this to database. Normally if I will select "Selection1"
the value="3"
will be selected and if I select "Selection2"
the value="4"
will be selected.
Now, I want that if I select "Selection1&2"
the value="3"
and value="4"
will be selected or post to database.
Any ideas or suggestions on how to do that?
<select class="form-control" id='Selection'>
<option value="3">Selection1</option>
<option value="4">Selection2</option>
<option value="5">Selection1&2</option>
</select>
Thank you
Upvotes: 0
Views: 362
Reputation: 911
If your third option acts as Select all option use Bootstrap frame work for select all functionality and for also better look and feel.
<div class="form-group">
<div class="col-md-4">
<select id="Selection" class="multiselect-ui form-control" multiple="multiple">
<option value="3">Selection1</option>
<option value="4">Selection2</option>
<!-- Following option can be removed -->
<!-- option value="5">Selection1&2</option -->
</select>
</div>
</div>
<script type="text/javascript">
$(function () {
$('.multiselect-ui').multiselect({
includeSelectAllOption: true
});
});
</script>
"Select All" will act as your third option
Upvotes: 1
Reputation: 54796
Use attribute multiple
and set name of your select
using []
:
<select class="form-control" id='Selection' name="myselect[]" multiple>
<option value="3">Selection1</option>
<option value="4">Selection2</option>
<!-- Following option can be removed -->
<!-- option value="5">Selection1&2</option -->
</select>
Printing value of myselect
on server:
print_r($_POST['myselect']);
you will see that you have an array with selected values.
Upvotes: 5