Emdadul Huq
Emdadul Huq

Reputation: 45

bootstrap-select select/deselect all option click can't firing event?

This is probably an easy question, but I can't find an answer anywhere or get it to work.

I'm using http://silviomoreto.github.io/bootstrap-select/ plugin.

How can I fire an event when product items select all/deselect all? I have tried with jquery click and change events like this:

$(document).on('click','#productCategory', function(event) {
    alert("test");
});

This is my Select list:

<select id="productCategory" multiple data-actions-box="true">
    <option>Laptop</option>
    <option>Tablet</option>
    <option>Computer</option>
</select>

Upvotes: 0

Views: 6036

Answers (3)

Mihai T
Mihai T

Reputation: 17687

don't really understand your question. but you want something like this ?

Let me know

$('#productCategory').selectpicker({
  style: 'btn-info',
  size: 4
});
$(".bs-select-all").on('click', function() {
    alert("ALL SELECTED");
});
$(".bs-deselect-all").on('click', function() {
    alert("ALL DESELECTED");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js">
</script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.11.2/css/bootstrap-select.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.11.2/js/bootstrap-select.min.js"></script>
<select id="productCategory" multiple data-actions-box="true">
    <option>Laptop</option>
    <option>Tablet</option>
    <option>Computer</option>
</select>

Upvotes: 0

Akivamu
Akivamu

Reputation: 588

You can refer here: http://silviomoreto.github.io/bootstrap-select/options/#events

$('#productCategory').on('changed.bs.select', function (e) {
  // do something...
});

Upvotes: 1

Thala
Thala

Reputation: 21

$(document).ready(function(){
    $("#productCategory").click(function(){
        alert("test");
    });

Try this code!

Upvotes: 0

Related Questions