Yii Framework Forum: Dependency Dropdown Country to State - Yii Framework Forum

Jump to content

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

Dependency Dropdown Country to State

#1 User is offline   vamsi 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 24-July 12

Posted 24 July 2012 - 06:00 AM

Hi friends,
I am completely new to yii.. Currently am working on a project and in that i want dependent dropdowns.. I have 2 tables tbl_country, tbl_states..

_form.php

<div class="row">
<?php echo CHtml::dropDownList('country','',CHtml::listData(Country::model()->findAll(array('order'=>'countryname ASC')),'country_id','countryname'),array('prompt'=>'Select', 'id'=>'countryid',
'ajax' => array(
'type'=>'POST',
'url'=>CController::createUrl('dynamicstates'),
'update'=>'#stateid',
'data'=>'js:$(this).serialize()',

))); ?>

</div>

<?php echo CHtml::dropDownList('state','',array(),array('prompt'=>'Select','id'=>'stateid')); ?>

controller.php

public function actionDynamicstates()
{


$data=Country::model()->findAll('country_id=:countryid',
array(':countryid'=>(int) $_POST['countryid']));



echo CHtml::tag('option', array('value' => 0), CHtml::encode('Select'), true); // for select

$data=CHtml::listData($data,'state_id','statename');
foreach($data as $value=>$name)
{
echo CHtml::tag('option',
array('value'=>$value),CHtml::encode($name),true);
}
}


Please help me to find the solution..

Thanks..
0

#2 User is offline   vamsi 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 24-July 12

Posted 30 July 2012 - 11:41 PM

Worst forum nobody replied f**k
0

#3 User is offline   hemc 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 88
  • Joined: 09-July 12
  • Location:New Delhi

Posted 01 August 2012 - 04:52 AM

www.yiiframework.com/wiki/24/

follow the steps.and check your code
Please don't add a reply to say thanks, There is already a +1 button to do same.
0

#4 User is offline   hemc 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 88
  • Joined: 09-July 12
  • Location:New Delhi

Posted 01 August 2012 - 05:00 AM

'update'=>'#stateid',
<?php echo CHtml::dropDownList('state','',array(),array('prompt'=>'Select','id'=>'stateid')); ?>

instead of this use following lines
'update'=>'#stateid',
<?php echo CHtml::dropDownList('stateid','',array()); ?>

Please don't add a reply to say thanks, There is already a +1 button to do same.
0

#5 User is offline   hemc 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 88
  • Joined: 09-July 12
  • Location:New Delhi

Posted 01 August 2012 - 05:04 AM

before starting new thread please cheak all related topic.
see this one
http://www.yiiframew...rom-state-name/
Please don't add a reply to say thanks, There is already a +1 button to do same.
0

#6 User is offline   new_user 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 01-August 12

Posted 01 August 2012 - 05:19 AM

@hemc
thanx for your answer
1

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