javascript - How to select value of dropdown using jQuery -
i have dropdown using boostrap. need store value select dropdown in variable, i'm trying print it.
window.alert($("#list_userinput_location option:selected").val()); it displays 'undefined'. if this:
window.alert($("#list_userinput_location option:selected").text()); it displays empty string. tried this:
window.alert($("#list_userinput_location").val()); displays 'undefined' again.
so confused.......... thoughts?
edit: here's fiddle https://jsfiddle.net/qmsqu/11/
in response jsfiddle: https://jsfiddle.net/qmsqu/12/
$("#list_userinput_location").val() is correct css selector , .val() returns content of value="...". not text inside <option> tag.
this requires <select> element has id of "list_userinput_location", i.e.
<select id="list_userinput_location">