Click here to Skip to main content
15,902,938 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi,
I have a HTML checkbox whose value bind from angularjs ng-model.
I want to enable or disable the HTML textbox according to that value of checkbox.

When page loads, value of checkbox may be true or false. Accordingly textbox should also be enabled or disabled.

And when user checks/unchecks the checkbox, the textbox should also get enabled or disabled.

This is my HTML page:
ASP.NET
<table class="tblDataEntry">
 <tr>
     <td class="tdCheck" colspan="2">
        <input type="checkbox" id="chkDashboard" data-ng-model="PropCollection.IsDashboardConfigured"  enableviewstate="true" tabindex="6" onclick="javascript:SetDashboardControlsEnable(this);" ondblclick="alert();" />Dashboard		
     </td>
 </tr>
 <tr>
     <td class="tdLabel">Server Name:</td>
     <td class="tdField">
        <input type="text" id="txtDashBoardServerName" data-ng-model="PropCollection.ServerName" clientidmode="Static" runat="server" class="aspTextbox" tabindex="7" maxlength="255" />
     </td>
 </tr>
</table>


What I have tried:

I tried calling a javascript function on onclick event of the checkbox. But event does not fire.
Posted
Updated 15-Apr-16 3:33am
Comments
Sergey Alexandrovich Kryukov 15-Apr-16 9:03am    
No you did not. If you did, you would write the code with JavaScript and everything in "What I have tried".
Or do you just want to keep what you really tried in secret?
—SA
Lokesh Zende 17-Apr-16 23:47pm    
yes..I want to keep it a secret ;)

1 solution

Well that seems like an odd way to do it! AngularJS handles this sort of thing for you automatically, using the ngDisabled[^] directive:
ASP.NET
<table class="tblDataEntry">
 <tr>
     <td class="tdCheck" colspan="2">
        <input type="checkbox" id="chkDashboard" data-ng-model="PropCollection.IsDashboardConfigured"  enableviewstate="true" tabindex="6" />Dashboard		
     </td>
 </tr>
 <tr>
     <td class="tdLabel">Server Name:</td>
     <td class="tdField">
        <input type="text" id="txtDashBoardServerName" data-ng-model="PropCollection.ServerName" data-ng-disabled="!PropCollection.IsDashboardConfigured" clientidmode="Static" runat="server" class="aspTextbox" tabindex="7" maxlength="255" />
     </td>
 </tr>
</table>
 
Share this answer
 
Comments
Lokesh Zende 17-Apr-16 23:46pm    
Yes.. This is what I want. I am new to angular. I thought I would work just like the javascript. But you saved me. :)

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900