Sunday, March 25, 2012

Jquery How to Select a dropdown selected value

Title:
How to get drop down list selected value using jquery

Description:
When we start working with jquery ,we may think how and where we have to use jquery libraries.Before going to use jquery methods,we should download and add latest version of jquery plugin from jquery.com.With out plug-in we could not use any methods of jquery reference.

Example:
In previous articles i have given Jquery Dropdownlist validation,JqueryUI autocomplete textbox.Jquery Get month or year,Hide and show div using jquery ,Jquery Declare variable.In this post i will show how to get the dropdownlist selected value using jquery.Below script will show  the selected value as alert while page loading

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="http://code.jquery.com/jquery-1.9.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
var ddlOrderText = $("#ddlChar option:selected").text();
alert(ddlOrderText );
var ddlOrderValue = $("#ddlChar option:selected").val();
alert(ddlOrderValue);
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="ddlChar" runat="server">
<asp:ListItem>Bhaskar</asp:ListItem>
<asp:ListItem>Aspdotnet</asp:ListItem>
<asp:ListItem>Sharepoint</asp:ListItem>
</asp:DropDownList>
</div>
</form>
</body>
</html>

1 comment:

Anonymous said...

Thanks a lot.Save a lot time for me..

Bel