Yii Framework Forum: Choose Second Drop Down Value Depend On Above Selected - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Choose Second Drop Down Value Depend On Above Selected

#1 User is offline   PMP 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 17-May 14

Posted 17 May 2014 - 03:29 AM

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>


0

#2 User is offline   Palraj Arockiaraj 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 14-June 12

Posted 18 May 2014 - 11:49 PM

View PostPMP, on 17 May 2014 - 03:29 AM, said:

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.yiiframew...ndent-dropdown/
This should help you on this.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users