i have a dependent dropdown between country and state and i want OTHER option in state dropdown,sothat when clicking on OTHER option open a textbox
_form.php
<div class="row">
<?php echo $form->labelEx($profile,'country'); ?>
<?php echo $form->dropDownList($profile,'country_id',
CHtml::listData(Country::model()->findAll(), 'id', 'printable_name'),
array(
'prompt' => 'Select Country',
'ajax' => array(
'type' => 'POST',
'url' => CController::createUrl('dynamicState'),
'update' => '#'.CHtml::activeId($profile,'state_id'),
//'data'=>array('state_id'=>'js:this.value'),
)
)
);
?>
<?php echo $form->error($profile,'country_id'); ?>
</div>
<div class="row" id="select" style="width:100%;">
<?php echo $form->labelEx($profile,'state'); ?>
<?php echo $form->dropDownList($profile,'state_id',array('prompt'=>'Select State','0' =>'other'),array( 'onChange' => 'javascript:description()',
'ajax'=>array(
'type'=>'POST',
'url'=>CController::createUrl('otherBox'),
'update'=>'#description_id',
)));?>
and controller UserController.php
public function accessRules()
{
return array(
array('allow', // allow all users to perform 'index' and 'view' actions
'actions'=>array('login','resetform','resetpassword'),
'users'=>array('*'),
),
array('allow', // allow all users to perform 'index' and 'view' actions
'actions'=>array('index','view','create','update','otherBox','dynamicState', 'logout','admin','delete'),
'users'=>array('@'),
),
array('deny', // deny all users
'users'=>array('*'),
),
);
}
public function actiondynamicState()
{
if(isset($_POST['UserProfile']['country_id'])){
$country_id = $_POST['UserProfile']['country_id'];
$data = State::model()->findAll('country_id=:country_id',array(':country_id' => $country_id));
$data = CHtml::listData($data, 'id','name');
echo CHtml::tag('option',array('value' => 0),CHtml::encode('Select State'),true);
foreach($data as $value => $state)
{
echo CHtml::tag('option',array('value' => $value),CHtml::encode($state), true);
}
}
}
public function actionotherBox()
{
if(isset($_POST['UserProfile']['state_id'])){
if($_POST['UserProfile']['state_id'] === 0)
$state_id = $_POST['UserProfile']['state_id'];
echo CHtml::textField('CustomState','',array('size'=>10));
}
}