Click here to Skip to main content
15,891,657 members
Articles / Programming Languages / Javascript
Alternative
Tip/Trick

Enable Disable Textboxes based on CheckBox using JavaScript

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
14 Dec 2011CPOL 48.1K   4
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)


Written By
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionThanks dear Pin
nomi_a22-Dec-13 23:42
nomi_a22-Dec-13 23:42 
GeneralThanks.. Pin
Member 102774706-Oct-13 23:00
professionalMember 102774706-Oct-13 23:00 
QuestionOne chk box multiple textbox Pin
Ali Ejaz10-May-12 5:28
Ali Ejaz10-May-12 5:28 
AnswerRe: One chk box multiple textbox Pin
nomi_a22-Dec-13 23:43
nomi_a22-Dec-13 23:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.