Disabling text box on click of checkbox not working using jquery -
this question has answer here:
i unable delete text , disable text box using jquery code, below code. alert working whether check or uncheck checkbox. please suggest.
<script> $(document).ready(function(){ var arr= new array('1','2','3','4','5'); for(var i=0;i<arr.length;i++) { $("#q4x1_"+arr[i]).click(function(){ if($("#q4x1_"+arr[i]).prop('checked',true)) { alert("hi"); $("#q4x2_"+arr[i]).val(''); $("#q4x2_"+arr[i]).prop('readonly',true); } else { $("#q4x2_"+arr[i]).val('testing'); $("#q4x2_"+arr[i]).prop('readonly',false); } }); } }); </script> </head> <body> <table border="1"> <tr> <td><input type="checkbox" id="q4x1_1"></td> <td><input type="text" id="q4x2_1"></td> </tr> <tr> <td><input type="checkbox" id="q4x1_2"></td> <td><input type="text" id="q4x2_2"></td> </tr> <tr> <td><input type="checkbox" id="q4x1_3"></td> <td><input type="text" id="q4x2_3"></td> </tr> <tr> <td><input type="checkbox" id="q4x1_4"></td> <td><input type="text" id="q4x2_4"></td> </tr> <tr> <td><input type="checkbox" id="q4x1_5"></td> <td><input type="text" id="q4x2_5"></td> </tr> </table> </body> </html>
you can use:
$('input:checkbox').change(function(){ var checked = $(this).prop('checked'); var nextinp=$(this).parent().next().find('input'); nextinp.prop('disabled', checked); if(checked) nextinp.val(''); });
Comments
Post a Comment