I have a PHP do while loop for generating text, radio and checkbox input fields. The text and radio fields are disabled by default and I want to enable them as I check the corresponding checkbox. I have assigned random IDs and tried many jQuery solutions but I'm still having problems.

**Code:**

```
<?php
$query = "SELECT * FROM `test` ";
$result = mysql_query($query);
$count = 0;
  do{
  $row = mysql_fetch_array($result);
  if($row){
    $id = $row['id'];
    $name = $row['name'];
?>

    <tr>
        <td><?php echo $name; ?></td>
        <td><input type="text" id="txt_<?php echo $count; ?>" class="txt form-control" name="txt" style="width:200px;" disabled /></td>
        <td><input type="radio" id="radio_<?php echo $count; ?>" class="rdo" name="rdo<?php echo $count; ?>" value="yes" disabled /></td>
        <td><input type="radio" id="radio_<?php echo $count; ?>" class="rdo" name="rdo<?php echo $count; ?>" value="no" disabled /></td>
        <td><input type="checkbox" id="check_<?php echo $count; ?>" class="checks" name="check" /></td>
    </tr>

<?php
    $count = $count + 1;
    }
}
while($row);
?>

```

**jQuery:**

```
<script>
    $('#check_<?php echo $count; ?>').on('change', function(){
        if($(this).is(':checked')){
            $('#txt_<?php echo $count; ?>').prop('disabled', false);
            $('#radio_<?php echo $count; ?>').prop('disabled', false);
        }else{
            $('#txt_<?php echo $count; ?>').prop('disabled', true);
            $('#radio_<?php echo $count; ?>').prop('disabled', true);
        }
    });
</script>

```

**My solution:**

```
    $(function() {
      $('input[type=checkbox]').change(function() {
        if (this.checked) {
          $(this).closest('tr').find('input[type=text]').prop('disabled', false);
          $(this).closest('tr').find('input[type=radio]').prop('disabled', false);
        } else {
          $(this).closest('tr').find('input[type=text]').prop('disabled', true);
          $(this).closest('tr').find('input[type=radio]').prop('disabled', true);
        }
      });
    });

```

This Function Worked charms :)