Reputation: 113
here's what I mean:
I have a few controls, for example,
<asp:DropDownList ID="ddlDate1" runat="server" />
<asp:DropDownList ID="ddlDate2" runat="server" />
<asp:DropDownList ID="ddlDate3" runat="server" />
in my javascript, I want to do something like this:
for (i = 1; i <= count; i++) {
something[i] = document.getElementById("<%= ddlDateRange" + i + ".ClientID %>");
}
any way I can make this work, or any alternatives?
Upvotes: 1
Views: 182
Reputation: 4984
Why not use jQuery and just do something like:
<asp:DropDownList CssClass="ddl" ID="ddlDate1" runat="server" />
<asp:DropDownList CssClass="ddl" ID="ddlDate2" runat="server" />
<asp:DropDownList CssClass="ddl" ID="ddlDate3" runat="server" />
$('.ddl').each(function(){
var ddl = $(this);
});
Upvotes: 1
Reputation: 17957
Put your dropdown lists into an array. Then you can populate a javascript array like so
var dropDownListIds = [];
<% foreach (DropDownList ddl in myListOfDropDowns) { %>
dropDownListIds.push('<%= ddl.ClientID %>');
<% } %>
Upvotes: 1