Skip to content

Instantly share code, notes, and snippets.

@juliorosseti
Created October 17, 2016 13:16
Show Gist options
  • Save juliorosseti/e245e511a1e7adcdf15d547326a4f7c3 to your computer and use it in GitHub Desktop.
Save juliorosseti/e245e511a1e7adcdf15d547326a4f7c3 to your computer and use it in GitHub Desktop.
Change selectpicker in "silviomoreto/bootstrap-select/issues/737" solution
<select class="form-control selectpicker" name="mynames[]"
multiple="multiple" onchange="changeSelectPicker(this)">
<option value="1">Count 1</option>
<option value="2">Count 2</option>
<option value="3">Count 3</option>
<option value="4">Count 4</option>
</select>
<script type="text/javascript">
// PROBLEM
$('.selectpicker').on("changed.bs.select", function (e, clickedIndex) {
console.log(this); // NO RETURN
});
// PROBLEM
$('.selectpicker').on("change", function (this) {
console.log(this); // NO RETURN
});
// SOLVED
function changeSelectPicker(that) {
var valuesArr = $(that).val();
console.log(valuesArr); // return selected values ["1", "3", "4"]
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment