disabled textbox
i hv written this piece of code. but it is for html checkbox and txtb开发者_高级运维ox. i want to hv the same functionality with asp.net txtbox and checkbox.how to do it?
<script type="text/javascript">
$(document).ready(function() {
var checkbox = $('#notify');
var textfield = $('#notifyemailaddress');
checkbox.click(function() {
if (checkbox.is(':checked')) {
textfield.removeAttr("disabled");
textfield.removeClass("email");
}
else {
textfield.attr("disabled", "disabled");
textfield.addClass("email");
}
});
});
</script>
<div>
<input type="checkbox" id="notify"/>
<label for="notify">Notify</label>
<input type="text" id="notifyemailaddress" disabled="disabled" class="email" style="width:25%" />
</div>
You need to find the correct id on asp.net and to do that you can use the ClientID of your asp.net controls. So you write something like
var checkbox = $('#<%=notify.ClientID%>');
Where <%=notify.ClientID%>, is print the final rendered id of your control, and the input is looks like
<asp:CheckBox runat="server" id="notify" />
On asp.net 4 you have also the ability to use static id to even avoid the ClientID, but take care to not use the same control id more than one time on the same page. You can read more on: http://msdn.microsoft.com/en-us/library/1d04y8ss.aspx
If you checkbox server control name is notifyemailaddress then use this:
var textfield = $('#<%= notifyemailaddress.ClientID %>');
精彩评论