Saturday, November 23, 2013

Jquery to get selected value from dropdown in asp.net

1 comment
Jquery code can be used to get the selected value from asp.net drop down list control. In this example I am displaying the selected text of drop down list on  the click of asp.net button control click event using jquery.

Jquery Code to Show Selected Value of Drop Down List control of asp.net:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script type="text/javascript" src="//code.jquery.com/jquery-1.10.2.min.js""></script>
<title></title>
<script type="text/javascript">
$(document).ready(function () {
$('#btngetval').click(function () {
var selectedval = $('#DropDownList1 option:selected').text();
alert(selectedval);
 });
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server" ClientIDMode="Static">
<asp:ListItem>INDIA</asp:ListItem>
<asp:ListItem>CHINA</asp:ListItem>
<asp:ListItem>USA</asp:ListItem>
<asp:ListItem>ITALY</asp:ListItem>
<asp:ListItem>GERMANY</asp:ListItem>       
</asp:DropDownList>
<asp:Button runat="server" ID="btngetval" Text="Submit"  />
</div>
</form>
</body>
</html>




1 comment:

  1. You're not getting the "value" in your code. You're getting the "text". Value and text are different.

    ReplyDelete