Yii Framework Forum: Dependent Drop Down List Using Ajax - Yii Framework Forum

Jump to content

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

Dependent Drop Down List Using Ajax Rate Topic: -----

#1 User is offline   edc413 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 27-January 13

Posted 17 March 2013 - 11:58 AM

Hi Guys,
I have struggled with this problem for a couple of days and I just seem to get it right. I am trying to create one drop down list that is dependent on another. I have followed through some of the examples given in a google search but they don't seem to work either.

Here is the code in my view file
<?php
$form=$this->beginWidget('CActiveForm', array(
'id'=>'play_form2',
'enableAjaxValidation'=>true,
));

$genClass = makesModels::model();
$criteria = "ParentID = 0";
$genData = Chtml::listData($genClass->findAll($criteria), 'ID', 'Description');
$options = array(
'id' => 'ParentID',
'ajax' => array('type'=>'POST'
, 'url'=>DealsController::createUrl('deals/dynamicModels')
, 'update'=>'#'.CHtml::activeId($model, 'ModelID')
)
);
echo CHtml::dropDownList('ID', '', $genData, $options);

echo $form->dropDownList($model, 'ModelID', array());

$this->endWidget();
?>




And Controller
public function actionDynamicmodels() {

$param_parent =$_POST['ParentID'];
$criteria = "ParentID=$param_parent";
$data = makesModels::model()->findAll();
$data = CHtml::listData($data, 'ID', 'Description');
foreach($data as $value) {
echo CHtml::tag('option',array('value'=>$value->ID,CHtml::encode($value->Description) , true) );

}

}




Any pointers are greatly appreciated
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