Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
-5
rated 0 times [  1] [ 6]  / answers: 1 / hits: 22396  / 11 Years ago, thu, august 29, 2013, 12:00:00

I have an HTML table where there is a checbox and a textbox in everyrow. The idea here is every time a checkbox is checked, the textbox will be disabled. Here is the code:



 <table>
<tr>
<td>Value1</td>
<td>Value2</td>
<td><input type=text class=textbox /></td>
<td><input type=checkbox class=Blocked onclick=myFunction(this)/></td>
</tr>
</table>


<script src=/Scripts/jquery-1.7.1.js></script>
<script type=text/javascript>
function myFunction(chk) {
//disable the textbox here
}
</script>


Can you help me with this? Also, if I unchecked the checbox, I want my textbox to be enabled back. Thanks!!


More From » jquery

 Answers
1

Would something like below work for you?



$('.Blocked').change( function() {
var isChecked = this.checked;

if(isChecked) {
$(this).parents(tr:eq(0)).find(.textbox).prop(disabled,true);
} else {
$(this).parents(tr:eq(0)).find(.textbox).prop(disabled,false);
}

});


JSFiddle: http://jsfiddle.net/markwylde/LCWVS/6/



Compacted, it would look a little like:



$('.Blocked').change( function() {
$(this).parents(tr:eq(0)).find(.textbox).prop(disabled, this.checked);
});


JSFiddle: http://jsfiddle.net/markwylde/LCWVS/4/


[#76018] Thursday, August 29, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dusty

Total Points: 739
Total Questions: 97
Total Answers: 85

Location: Angola
Member since Wed, Apr 13, 2022
2 Years ago
;