Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
174
rated 0 times [  181] [ 7]  / answers: 1 / hits: 124776  / 7 Years ago, wed, january 25, 2017, 12:00:00

I used e.target.value to retrieve the current selected value from bootstrap-select but it returned the first selected value i.e. the alert kept displaying item 1, when item 1 and item 2 where selected even when item 2 was the most recently selected.



How can I get the value for the recent selection and how can I get how many options are selected?



   <select multiple class=selectpicker multiple data-selected-text-format=count > 1>
<option value=item 1>Item 1</option>
<option value=item 2>Item 2</option>
<option value=item 3>Item 3</option>
<option value=item 4>Item 4</option>
<option value=item 5>Item 5</option>




$('.selectpicker').change(function (e) {
alert(e.target.value);
});

More From » jquery

 Answers
3

I think the answer may be easier to understand like this:





$('#empid').on('click',function() {
alert($(this).val());
console.log($(this).val());
});

<script src=https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js></script>
<select id=empid name=empname multiple=multiple>
<option value=0>item0</option>
<option value=1>item1</option>
<option value=2>item2</option>
<option value=3>item3</option>
<option value=4>item4</option>
</select>
<br />
Hold CTRL / CMD for selecting multiple fields





If you select item1 and item2 in the list, the output will be 1,2.


[#59218] Sunday, January 22, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
alli

Total Points: 409
Total Questions: 101
Total Answers: 105

Location: The Bahamas
Member since Tue, Apr 27, 2021
3 Years ago
alli questions
Sat, Apr 23, 22, 00:00, 2 Years ago
Mon, May 18, 20, 00:00, 4 Years ago
Tue, Mar 24, 20, 00:00, 4 Years ago
Fri, Jan 24, 20, 00:00, 4 Years ago
;