Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / Javascript

Enable Disable Textboxes based on CheckBox using JavaScript

5.00/5 (1 vote)
14 Dec 2011CPOL 48.4K  
This code also performs the same functionality: window.onload = function() { var check = document.getElementById(); check.onchange = function() { if (this.checked == true) ...
This code also performs the same functionality:
JavaScript
<script type="text/javascript">
        window.onload = function() {
            var check = document.getElementById("<%=checkbox1.ClientID %>");
            check.onchange = function() {
                if (this.checked == true)
                    document.getElementById("<%=textbox1.ClientID %>").disabled = false;
                else
                    document.getElementById("<%=textbox1.ClientID %>").disabled = true;
            };
        };
</script>   


ASP.NET
<asp:checkbox checked="false" id="checkbox1" runat="server"  />
        <asp:textbox id="textbox1" enabled="false" text="Test" runat="server" />

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)