开发者

jquery asp.net combo box question

I have a small form with a combo box (ASP.NET Drop Down List control) and a text box (with a DIV id txtName). When the selected index of the combo box changes, I want to clear out the text box.

I understand that the follow clears the text box value:

$("#txtName").val('');

T开发者_C百科he thing is the combo box. It contains a list of integers representing the months of the year. The drop down control is called ddlMonths.

$("#ddlMonths").change(function() {
    $("#txtName").val('');
});

I thought by using change, an onSelectedIndexChange event handler would be associated with this control.

I also tried (because I've ran into the client id being mangled in ASP.NET w/ jQuery) this:

$("#<%=ddlMonths.ClientID%>").change(function() {
    $("#<%=txtName.ClientID%>").val('');
});

and neither approach seems to be working. Am I missing something?


I just realized what my problem was!

The aforementioned code was in a javascript client block, but, I didn't have:

$(document).ready( function() {

// I put my code in here and then it worked.  My problem was more than likely that 
// my code executed *before* the controls were rendered, and I need to have the code 
// ready to execute *after* the document completely rendered.

});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜