js how to get selectpicker value
$(document).on('change', '#input_id', function() {
var selected = $('#input_id').val();
});
js how to get selectpicker value
$(document).on('change', '#input_id', function() {
var selected = $('#input_id').val();
});
selectpicker set value jquery
The value is correctly selected, but you didn't see it because the plugin hide the real select and show a button with an unordered list, so, if you want that the user see the selected value on the select you can do something like this:
//Get the text using the value of select
var text = $("select[name=selValue] option[value='1']").text();
//We need to show the text inside the span that the plugin show
$('.bootstrap-select .filter-option').text(text);
//Check the selected attribute for the real select
$('select[name=selValue]').val(1);
Edit:
Like @blushrt points out, a better solution is:
$('select[name=selValue]').val(1);
$('.selectpicker').selectpicker('refresh')
Edit 2:
To select multiple values, pass the values as an array.
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us