title: Saving data of dependent drop-down - Yii
body: <p>I am implementing a dependent drop-down and want to save their IDs in the table CANDIDATE.<br/>
  I have a table named as CENTER which has two columns ID, NAME.<br/>
  My other table is DISTRICT which has three columns ID, NAME and CENTER_ID.<br/> 
  By selecting the CENTER , I am populating the DISTRICT drop-down but the district_id is not being saved in the table CANDIDATE .<br/><br/>
  <strong>_form</strong></p>
  
  <pre><code>&lt;div class="row"&gt;
      &lt;?php echo $form-&gt;labelEx($model, 'district_id'); ?&gt;
      &lt;?php
  
      $dist = CHtml::listData(Center::model()-&gt;findAll(array('order' =&gt; 'id')), 'id', 'name');
      echo $form-&gt;dropDownList($model, 'center_id', $dist, array(
          'prompt' =&gt; '–select district–',
          'ajax' =&gt; array('type' =&gt; 'POST',
              'url' =&gt; CController::createUrl('candidate/districts'),
              'update' =&gt; '#center_id',
  
          )
  
      ));
      ?&gt;
      &lt;?php
      echo CHtml::dropDownList('center_id','', array());
      ?&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>CandidateController</strong></p>
  
  <pre><code> public function actionDistricts() {
      $centers = District::model()-&gt;findAll('center_id =:id', array(':id' =&gt; (int) $_POST['Candidate']['center_id']));
      $return = CHtml::listData($centers, 'id', 'name');
      foreach ($return as $centerId  =&gt; $centerName) {
          echo CHtml::tag('option', array('value' =&gt; $centerId), CHtml::encode($centerName), true);
      }
  }
  </code></pre>