Hello i’m trying to use autocomplete dropdownlist plugin that name is ufd.
Anyway, I have dropdownlist and i want to get this selected value (or text) on codebehind click_event.
if i can remove all selected attr from dropdownlist and add selected attr to selected option, this will work.But this removeAttr doesn’t work:( Please help me.
$(function () {
var element = $("#DropDownList1");
$(element).change(function () {
$(element).find('option').removeAttr('selected'); //this is not working
$(element + "option[value=" + $(element).val() + "]").attr("selected", "selected");
});
});
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
codebehind:
protected void Page_Load(object sender, EventArgs e)
{
using (TalepService tService = new TalepService())
{
DropDownList1.DataSource = tService.ddlTalepDurumDoldur();
DropDownList1.DataTextField = "talepDurumu";
DropDownList1.DataValueField = "talepDurumID";
DropDownList1.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string text = DropDownList1.SelectedItem.Text;
string value = DropDownList1.SelectedValue;
}
You are creating jQuery objects from jQuery objects, which is having an issue on this line (I’m assuming):
Because
elementis a jQuery object (keyword, object) and you are adding a string to that object.Try this:
Here is a demo: http://jsfiddle.net/LjhwW/1/
While creating this demo I realized the same thing as “am not i am” (in the comments). Why are you manually changing the selected option element for the
changeevent, the browser will do this anyway.