dependent dropdownlist not working (jQuery problem)

I tried to make a dependent dropdown according to this tutorial http://www.yiiframework.com/wiki/24/ but when I place this code, the jQuery doesn’t work:


	

<div class="row">

		<?php

			$htmlOptions = array('empty' => 'Please Select an option', 'ajax' =>  array("url" => $this->createUrl("user/subcategoriesByCategory"), "type" => "POST", "update" => "#Facts_sub_category"));

		?>

		<?php echo $form->labelEx($model,'main_category'); ?>

		<?php echo $form->dropDownList($model,'main_category', FactsQuestionsCategory::model()->getMainCategoryOptions(), $htmlOptions) ?>

		<?php echo $form->error($model,'main_category'); ?>

</div>

The "subcategoriesByCategory" function is never called

It may be dumb, but are you sure jQuery is loaded? Make sure it is loaded, and check the error console for errors.

yes, jQuery is loaded, because if I write the following code it works:

$(document).ready(function(){

alert(‘aaaa’);

});

However, jQuery stops working as soon as I put the code of the dependent dropdown

Are you sure "user/subcategoriesByCategory" points to the valid action? Is the request sent when you change the dropdown options? Can you show the code of "user/subcategoriesByCategory" action?

I think the request isn’t sent when I change the dropdown options. This is the code:


	public function actionSubcategoriesByCategory()

	{	

		echo "<option value='1'>test1</option>";

		echo "<option value='2'>test2</option>";

		echo "<option value='3'>test3</option>";

		echo "<option value='4'>test4</option>";

	}

Check if code responsible for loading the content is present. Look for any potential errors in the console (use Firebug or other similar tool).

Hi,

can u show ur dependentcontroller’s action code ,and ur dropdown list code…so we can exactly find out solution.


<div class="form"> 

<?php $form=$this->beginWidget('CActiveForm', array(

	'id'=>'facts_contribute',

)); ?>


	<p class="note">Fields with <span class="required">*</span> are required.</p>


	<?php echo $form->errorSummary($model); ?>

	

	<div class="row">

		<?php

			$htmlOptions = array('empty' => 'Please Select an option', 'ajax' =>  array("url" => $this->createUrl("user/subcategoriesByCategory"), "type" => "POST", "update" => "#Facts_sub_category"));

		?>

		<?php echo $form->labelEx($model,'main_category'); ?>

		<?php echo $form->dropDownList($model,'main_category', FactsQuestionsCategory::model()->getMainCategoryOptions(), $htmlOptions) ?>

		<?php echo $form->error($model,'main_category'); ?>

    </div>

    <div class="row">

		<?php echo $form->labelEx($model,'sub_category'); ?>

		<?php echo $form->dropDownList($model,'sub_category', array(), array('empty' => 'Please Select an option')) ?>

		<?php echo $form->error($model,'sub_category'); ?>

    </div>    

    <div class="row buttons">

       <?php echo CHtml::submitButton('Ok'); ?>

    </div>

    <?php $this->endWidget(); ?>

</div>



Is your $model class called Facts?

yes

hi

َAre you sour that id of second Dropdown is "Facts_sub_category" ??