Reputation: 111
I have the following issue where i cannot retrieve the selected array from select2 in my JS.
<select class="js-example-basic-multiple"
name="states[]"
multiple="multiple"
style="width:500px;">
<option>"dynamic value"</option>
<option>"dynamic value2"</option>
And the associated script:
var caseCodes = $('.js-example-basic-multiple option:selected').text()
The above javascript function retrieves all my selected values as a single long string.
Is there any way i can retrieve the array and loop through it to find each individual selected value?
Upvotes: 1
Views: 166
Reputation: 26360
Just read the <select>
's value :
$('.js-example-basic-multiple').val()
Upvotes: 3