Choose Second Drop Down Value Depend On Above Selected

Hello,

Am new in Yii.

I have a form in which I have two dropdown (1)skill type and (2)skill

Onchange of first (1)skill type, I want to load the second (2)skill dropdown.

But skill dropdown should contain values from DB whose skill_type is selected above.

in DB , I have :

Skill_Type table as:

skill_type_id skill_type

1 language

2 database

and Skill table as:

skill_id skill skill_type_id

1 c++ 1

2 c 1

3 SQL 2

so want to load skill dropdown values depend on Skill_type selected values.

currentluy I have just shown all values from skill table [which is wrong here]




<b>Skill Type :</b>

		<?php

		$other_option =array('Other' => 'Other value');			

		$selectedOptions= CHtml::listData(SkillType::model()->findAll(array('order' => 'skill_type_id')),'skill_type_id','skill_type');

		$selectedOptions = array_merge( $selectedOptions, array( "Other" => "Other" )) ;	

		echo $form->dropDownList(SkillType::model(),'skill_type',$selectedOptions,

		$htmlOptions=array('id'=>'skill_type_name','prompt'=>'Select','onchange'=>'load_div()')

		); ?> 

	<br>

	<div id='skill_info' style="display:none" class='form-row-new' >

		<div id='id_skill_name' onchange='load_other_skill()'>

			<b>Skill : </b>		

			<?php 

			$other_option = array('Other Skill'=>'Other Skill',);

			$skills_from_db=CHtml::listData(Skill::model()->findAll(array('order' => 'skill_id')),'skill_id','skill');

			$skills_from_db=array_merge($skills_from_db,$other_option);

			echo $form->dropDownList(Skill::model(),'skill_id',$skills_from_db,$htmlOptions=array('id'=>'skill_name',));

			?> 

		</div>




Hi,

Please check this post

http://www.yiiframework.com/wiki/24/creating-a-dependent-dropdown/

This should help you on this.