Yii Framework Forum: Dependent Dropndown With Other Option - Yii Framework Forum

Jump to content

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

Dependent Dropndown With Other Option Rate Topic: -----

#1 User is offline   Mayank Khatri 

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

Posted 04 January 2013 - 12:14 PM

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));
}
}
Mayank Khatri
Hawks Vision
Skpype - sns_bdm
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