Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Kindly let me how I can enable/disable a textbox on checkbox click in mvc..I am populating data in a list and now to need to fill data in the textbox of the row where checkbox is checked..kindly help in implementing the same by passing the checkbox checked/unchecked bool to controller and then enable/disable textbox...solutions in angular.js and jscript are also welcomed..

What I have tried:

I have tried extracting the checkbox check/uncheck to viewbag but it does not supports it...unable to get how to implement the above...
Posted
Updated 6-Aug-16 7:33am
Comments
Karthik_Mahalingam 6-Aug-16 12:20pm    
post the code.

1 solution

For Enable/Disable an element , Angular Controller logic is not required, ng attribute will does the job

HTML
<input type="checkbox" ng-click="flag1=!flag1" />
<input type="text"   ng-disabled="flag1">

Demo:- JSFiddle[^]
 
Share this answer
 
Comments
Member 11114915 - Tanvi 9-Aug-16 7:04am    
Thanks Karthik for the suggestion. Here I have few fields populating from database and passed through controller . A foreach loop is used in view to get the data row wise and checkbox and textbox enabling disabling feature is required row wise. But suggested implementation is working for only first checkbox not for others. Kindly suggest here...

@foreach (var item in Model) {

<tr>

<td>
@Html.DisplayFor(modelItem => item.itemname)
</td>

<td>
<img src="@Url.Content(item.ImgLocation)" alt="IMAGES" />
</td>
<td>
<input type="checkbox" ng-click="flag1=!flag1"/>
<input type="text" ng-disabled="!flag1">
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
</td>
</tr>


}
Karthik_Mahalingam 9-Aug-16 7:35am    
Controller means mvc controller or angular controller
Member 11114915 - Tanvi 9-Aug-16 7:58am    
MVC controller
Karthik_Mahalingam 9-Aug-16 8:11am    
ok wait
Karthik_Mahalingam 9-Aug-16 8:28am    
try this

<input type="checkbox" ng-click="funEnable($event)" />
<input type="text" >

$scope.funEnable = function (obj)
{
obj.target.parentElement.getElementsByTagName('input')[1].disabled = obj.target.checked;

}

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