Reputation: 358
I am using bootstrap 3 and listgroup.js (https://github.com/rickardn/listgroup.js) to turn a select dropdown visually into a list. However, as soon as I add class="list-group" to the select, my javascript is no longer able to get the selected value.
HTML
<select id="selecteduser" name="selecteduser" class="list-group">
<option value="user1">user1</option>
<option value="user2">user2</option>
<option value="user3">user3</option>
</select>
JS
$("#selecteduser").change(
function() {
//get the selected value
var selectedValue = this.value;
//make the ajax call
alert("You selected " + selectedValue);
}
);
The listgroup.js makes reference to the actual select being hidden, but how can I get the selected value from this hidden select in my Javascript?
Upvotes: 0
Views: 604
Reputation: 1661
According to list-group.js plugin documentation the javascript API not implemented yet:
More to come Because this project just got off the ground not everything have been documented fully. Examples of functions that exist but which will be described here incrementally are
The JavaScript API
But here is quick workaround
$(".list-group > a").on('click', function() {
alert("You selected " + $(this).data('value'));
});
https://jsfiddle.net/v8tbsktq/
Upvotes: 1