65.9K
CodeProject is changing. Read more.
Home

Enable Disable Textboxes based on CheckBox using JavaScript

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.85/5 (9 votes)

Dec 10, 2011

CPOL
viewsIcon

68921

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.
<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...
<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.