I have the following in my code:
<asp:DropDownList id="City" runat="server">
I tried using the following to get the key from the key value but it shows up as undefined although I selected from the dropdown
var city = $("#city option:selected").val();
alert(city);
You should simply use the
.val()method on theselectelement itself, rather than searching for theoption:selectedchild (as you’re currently doing).IDs in CSS are also case-sensitive.