I want to get the selected value from ajax combobox selected item using javascript in asp.net c#
here is my code
<asp:ComboBox ID="dropdown_dest" runat="server" Width="90%" onfocusout="blurFunction()" AutoCompleteMode="SuggestAppend" CssClass="ComboboxWidth" DropDownStyle="DropDownList" Height="15px" MaxLength="50">
</asp:ComboBox>
function blurFunction()
{
var ddlReport = document.getElementById("<%=dropdown_dest.ClientID%>").value;
alert(ddlReport);
}
in alert it is showing undefined.
Please help me to solve me this error
Thank You.
If you can use jquery, you can do it this way:
<asp:ComboBox ID="dropdown_dest" runat="server" Width="90%" onfocusout="blurFunction()" AutoCompleteMode="SuggestAppend" CssClass="ComboboxWidth" DropDownStyle="DropDownList" Height="15px" MaxLength="50">
</asp:ComboBox>
function blurFunction()
{
var ddlReport = $("#" + "<%=dropdown_dest.ClientID%>").find("option:selected").val();
alert(ddlReport);
}
I have not tested.
<asp:ComboBox ID="dropdown_dest" runat="server" Width="90%" onfocusout="blurFunction(this)" AutoCompleteMode="SuggestAppend" CssClass="ComboboxWidth" DropDownStyle="DropDownList" Height="15px" MaxLength="50">
</asp:ComboBox>
<script>
function blurFunction(e) {
var val = e.options[e.selectedIndex].value;
console.log(val);
}
</script>
using "this" will skip jquery loop and js script can be put in separate file.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.