Dependent Checkboxes


Iam trying to implement dependent check boxes in Yii. I have 2 tables named category and sub category. Categories are listed as checkboxes using the code

<?php echo CHtml::checkBoxList(




                              array( 'checkAllLast'=&gt;false,                                     




When selecting one checkbox the corresponding subcategories related to that category must list as check boxes.How can I implement it.

Category table contains category_id and category and Sub_category table contains subcategory_id, category_id and subcategory

I’ll implement this using jquery.

If you populate categories checkboxes with a cycle:

<input type="checkbox" data-index="1" class="categories">cat 1

<input type="checkbox" data-index="2" class="categories">cat 2

<input type="checkbox" data-index="3" class="categories">cat 3


and subcategoies checkbox with a cycle:

<input type="checkbox" data-parent="1">subcat 1 of 1

<input type="checkbox" data-parent="1">subcat 2 of 1

<input type="checkbox" data-parent="2">subcat 1 of 2

<input type="checkbox" data-parent="2">subcat 2 of 2

<input type="checkbox" data-parent="3">subcat 1 of 3

<input type="checkbox" data-parent="3">subcat 2 of 3

So clicking on a category checkbox:

$('.categories').on('click', function(ev) {

         $('input[data-parent='+$(this).attr('data-index')+']').checked = 1;