I have a jQuery Mobile code like this:
<select name="selectmenu1" id="selectmenu1">
<option value="o1">
a
</option>
<option value="o2">
b
</option>
<option value="o3">
c
</option>
<option value="o4">
d
</option>
</select>
Now I want to get the selected value after the user changed the selection.
How to do this with jQuery?
It's very simple...
$("#selectmenu1").change(function() {
var selected = $(this).val(); // or this.value
});
jsFiddle.
If you wanted the selected element's text node(s), use this instead...
$("#selectmenu1").change(function() {
var selected = $(this).find(":selected").text();
});
jsFiddle.
$('#selectmenu1').on('change', function(){
alert( this.value );
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With