title: Dependent dropdown for country and state in yii 1.13
body: <p>I had created two database tables as,</p>
  
  <ol>
  <li>Country</li>
  <li>State</li>
  </ol>
  
  <p>In Country table i had countryid &amp; cname field. In State table i had state_id, state_name &amp; country_cid.</p>
  
  <p>Now i need to make a dependent dropdown i.e. when i select country dropdown box, then the particular state for that country should be displayed. I had done below coding. But it displays only country and not displays state.</p>
  
  <p>This is in <strong>views/sample/register.php</strong> file.</p>
  
  <pre><code>&lt;div class="row"&gt;
      &lt;?php echo $form-&gt;labelEx($model,'countryid'); 
      $opts = CHtml::listData(Country::model()-&gt;findAll(),'countryid','cname');
      echo $form-&gt;dropDownList($model,'country_id',$opts,
          array(
                  'prompt'=&gt;'Select Country',
                  'ajax' =&gt; array(
                  'type'=&gt;'POST',
                  'url'=&gt;CController::createUrl('SampleController/dynamicSubcategory'),
                   array('coountry_id'=&gt;'js:this.value'),
                   'dataType' =&gt; 'JSON',
                   'success'=&gt;'js:function(data)'
                   . '{'
                   .  'var html="&lt;option value=&gt;-----Select city-----&lt;/option&gt;";'
                   .  '$.each(data,function(i,obj)'
                   .  '{'
                   .      'html+="&lt;option value=\'"+obj.id+"\'&gt;"+obj.name+"&lt;/option&gt;";'
                   .  '});'
                   .  '$("#state_id").html(html);'
                   .  '}'
                   )));
      echo $form-&gt;error($model,'country_id'); ?&gt;
  &lt;/div&gt;
  
  &lt;div class="row"&gt;
      &lt;?php echo $form-&gt;labelEx($model,'state_id'); 
      echo CHtml::dropDownList('state_id','', array());
      echo $form-&gt;error($model,'state_id'); ?&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>This is in <strong>controllers/SampleController.php</strong> file</p>
  
  <pre><code>public function actiondynamicSubcategory()
  {
          $countryId=$_POST['coountry_id'];
          $criteria=new CDbCriteria();
          $criteria-&gt;select=array('state_id,state_name');
          $criteria-&gt;condition='country_cid='.$countryId;
          $criteria-&gt;order='state_name';
          $cityAry= State::model()-&gt;findAll($criteria);
          $ary=array();
          foreach($cityAry as $i=&gt;$obj)
          {
              $ary[$i]['state_id']=$obj-&gt;id;
              $ary[$i]['state_name']=$obj-&gt;name;            
          }
          echo json_encode($ary);
  }
  </code></pre>
  
  <p>I had created Country model &amp; State model. I had analyzed many sites. But i can't get right. Please anybody help.</p>