开发者

How do I trigger a Jquery function with a Drop down list?

I have 2 asp:DropdownLists with an OnSelectedIndexChanged attribute. When that is triggered I would like to run a jquery function that would let the user know the data is being processed. How do I jump to my jQuery function and is there a way I don't have to use the unique id?

<asp:DropDownList ID="ddlFirst" r开发者_C百科unat="server" OnSelectedIndexChanged="ddlChange"> 
    <asp:ListItem>All</asp:ListItem>
    <asp:ListItem>None</asp:ListItem>
</asp:DropDownList>

<asp:DropDownList ID="ddlSecond" runat="server" OnSelectedIndexChanged="ddlChange"> 
    <asp:ListItem>All</asp:ListItem>
    <asp:ListItem>None</asp:ListItem>
</asp:DropDownList>

$(document).ready(function () {
$("???").change(function () {
    //code
});
});


Give them a class and use $('.yourClass')


You don't have AutoPostBack="true" attribute attached to your DDLs, so I have no idea what are you going to notify your user about. Anyway

<asp:DropDownList ID="ddlFirst" onchange="myFunc();">
</asp:DropDownList>

function myFunc() {
   // insert JS code here
}


First, assign a CssClass -

<asp:DropDownList ID="ddlFirst" CssClass="myDropDown" runat="server" 
              OnSelectedIndexChanged="ddlChange"> 
    <asp:ListItem>All</asp:ListItem>
    <asp:ListItem>None</asp:ListItem>
</asp:DropDownList>

<asp:DropDownList ID="ddlSecond" CssClass="myDropDown" runat="server" 
      OnSelectedIndexChanged="ddlChange"> 
    <asp:ListItem>All</asp:ListItem>
    <asp:ListItem>None</asp:ListItem>
</asp:DropDownList>

Then, do the following -

$(document).ready(function () {
    $(".myDropDown").change(function () {
        // code to display user message
    });
});


Did you try this?

$("select").change(function () {

});


Give the ddl a class, then do the following:

$(document).ready(function () {
$("select.myClassName").change(function () {
    //code
});
});


Hey u can use something like this $(“select[id$='ddlfirst']”)


Using ASP.net there is always this option:

<asp:DropDownList ID="ddlFirst" runat="server" OnSelectedIndexChanged="ddlChange"> 
  <asp:ListItem>All</asp:ListItem>
  <asp:ListItem>None</asp:ListItem>
</asp:DropDownList>

$(document).ready(function () {
  $("#<%= ddlFirst.ClientID %>").change(function () {
    //code
  });
});

This will dynamically load the DDL's ID into the javascript that will be loaded onto the page. I just have my javascript functions on the same page as the asp.net code

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜