dimanche 19 avril 2015

How to get all selected values using Bootstrap Multiselect and use it in AJAX

I am using Bootstrap Multiselect, this is my setup in my HTML:

<div class="form-group">
<select class="form-control" id="bldg_type" multiple="multiple">{% for type in buildings %}
<option value="{{type.bldg_type}}">{{type.bldg_type}}</option>{% endfor %}

I wanted to use the selected values for my query, the snippet of my Ajax code:

url: "cnt_bldg/",
type: "GET",
dataType: "JSON",
data: {
'brgy_id': brgy_id,
'bldg_type': $('#bldg_type option:selected').val()

The problem with $('#bldg_type option:selected').val() is I can only get 1 value. For e.g. I check Market and Police Station in my select option, and looked it in my console http://ift.tt/1Jl0Xry". It only gets the Market.

How do I get all the values and use it for my query?

BTW, I'm using Django. I have read this answer already, but I don't know how to use the result in my AJAX code above.

Aucun commentaire:

Enregistrer un commentaire