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

4.85/5 (9 votes)
10 Dec 2011CPOL 68.9K  
JavaScript
Welcome again, here is one more trick to enable or disable the multiple textboxes based on the check box event.

Please write the following code in Script area of the page.

JavaScript
<script type="text/javascript">
    function enableDisable(bEnable, textBoxID, textBoxID2)
    {
         document.getElementById(textBoxID).disabled = !bEnable
         document.getElementById(textBoxID2).disabled = !bEnable
    }
    </script>


Put the controls as shown below in the Form area...

C#
<asp:TextBox ID="t1" Text="" runat="server" />
 <asp:TextBox ID="t2" Text="" runat="server" />
 <asp:CheckBox ID="chk1" Checked="true" onclick="enableDisable(this.checked, 't1','t2');" runat="server" />


and let it behave as it is...it's done....

Browse the page and check that out!
Please visit me at ..... http://codeassistant.blogspot.com.

License

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