Click here to Skip to main content
15,892,072 members
Articles / Programming Languages / Javascript
Tip/Trick

Enable Disable Textboxes based on CheckBox using JavaScript

Rate me:
Please Sign up or sign in to vote.
4.85/5 (9 votes)
10 Dec 2011CPOL 68K   4   7
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)


Written By
Technical Lead IntelliMedia Networks, Inc
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

 
QuestionRegarding to demo Pin
ankitpatel101011-Oct-12 22:28
ankitpatel101011-Oct-12 22:28 
Questionhi dude .. Pin
ankitpatel101011-Oct-12 22:26
ankitpatel101011-Oct-12 22:26 
AnswerRe: hi dude .. Pin
Ravi Tuvar14-Oct-12 22:28
professionalRavi Tuvar14-Oct-12 22:28 
GeneralReason for my vote of 5 good and simple logic Pin
arun-ice29-Jan-12 21:56
arun-ice29-Jan-12 21:56 
GeneralReason for my vote of 5 Good solution - better and more read... Pin
Ed Nutting21-Dec-11 0:24
Ed Nutting21-Dec-11 0:24 
Generalmy 5+.. Pin
Prince Antony G13-Dec-11 18:59
Prince Antony G13-Dec-11 18:59 
GeneralReason for my vote of 5 simple logic. Pin
Prince Antony G13-Dec-11 18:54
Prince Antony G13-Dec-11 18:54 

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.