Bootstrap-select: How get clicked select option in multiple?

Created on 25 Nov 2016  路  4Comments  路  Source: snapappointments/bootstrap-select

Hello guys.. I have a multiple select and I want to get the clicked option value. No all of them... I have tried many ways but nothing works...

Most helpful comment

Found solution here - stackoverflow.com

Some modification:

$(".selectpicker").on("changed.bs.select", function(e, clickedIndex, newValue, oldValue) {
   var sel = $(this).find('option').eq(clickedIndex).val();
   console.log(sel+" "+newValue);
});

All 4 comments

$('selector').val()
it return Array if multiple set to true else a string.

is that deliberate? shouldn't it always return an array?

Isn't Rafsonic looking for the latest clicked option value, i.e. the value of the option that was selected? He did write "No all of them". Currently clickedIndex is returned on the event changed.bs.select, but this isn't the value of the actual select option.

Found solution here - stackoverflow.com

Some modification:

$(".selectpicker").on("changed.bs.select", function(e, clickedIndex, newValue, oldValue) {
   var sel = $(this).find('option').eq(clickedIndex).val();
   console.log(sel+" "+newValue);
});
Was this page helpful?
0 / 5 - 0 ratings

Related issues

AndreasPresthammer picture AndreasPresthammer  路  3Comments

qiyuan4f picture qiyuan4f  路  4Comments

ddinchev picture ddinchev  路  3Comments

alex-piccione picture alex-piccione  路  4Comments

EmilMoe picture EmilMoe  路  4Comments