title: cakephp Ajax: city select box not populating when state is selected
body: <p>I'm trying to populate the city select box based on the selected state (which is also a select box) using Ajax. When i select state, the city select box is not being populated.</p>
  
  <p>There are 5 models below: Student, MerryParent, MerryClass, State, City. All of them are related to one another.</p>
  
  <p>Can someone please tell me on what am I doing wrong? thank you. </p>
  
  <p>The following are the models:
  student.php</p>
  
  <pre><code> &lt;?php
   class Student extends appModel{
  var $name='Student';
  var $belongsTo=array('MerryParent','State','City','MerryClass');
  
            }
        ?&gt;
  </code></pre>
  
  <p>merry_parent.php</p>
  
  <pre><code>     &lt;?php
       class MerryParent extends appModel{
  var $name='MerryParent';
  $hasMany=array(
          'Student'=&gt;array(
          'className'=&gt;'Student',
          'foreignKey'=&gt;'merry_parent_id'
                  )
              );
  $belongsTo=array('State','City','MerryClass');
  
                       ?&gt;
  </code></pre>
  
  <p>merry_class.php</p>
  
  <pre><code>         &lt;?php
              class MerryClass extends AppModel{
           var $name='MerryClass';
           var $hasMany=array
      ('Student'=&gt;array(
              'className'=&gt;'Student',
              'foreignKey'=&gt;'class_id'
              ),
       'MerryParent'
      );
          var $belongsTo=array('State','City');
          //var $displayField='class_name';
             }
            ?&gt;
  </code></pre>
  
  <p>city.php</p>
  
  <pre><code>      &lt;?php
          class City extends AppModel{
      var $name='City';
      var $belongsTo='State';
      var $hasMany=array('MerryParent','MerryClass',
              'Student'=&gt;array(
                  'className'=&gt;'Student',
                  'foreignKey'=&gt;'city_id'
                  )
              );
                   }
          ?&gt;
  </code></pre>
  
  <p>state.php</p>
  
  <pre><code>               &lt;?php
                        class State extends AppModel{
                           var $name='State';
                           var $hasMany=array(
              'MerryParent',
              'MerryClass',
              'City'=&gt;array(
              'className'=&gt;'City',
              'foreignKey'=&gt;'state_id'
              //'dependent'=&gt;true
              ),
              'Student'=&gt;array(
              'className'=&gt;'Student',
              'foreignKey'=&gt;'state_id'
              )
          );
  
                }
               ?&gt;
  </code></pre>
  
  <p>The controllers
  students_controller.php</p>
  
  <pre><code>&lt;?php
  class StudentsController extends AppController{
   var $name='Students';
   var $helpers = array('Html','Form','Ajax','Javascript');
   var $components=array('RequestHandler');
  
  function getcities(){
  
      $options=$this-&gt;Student-&gt;City-&gt;find('list',
                                      array
                                      ('conditions'=&gt;array(
                                                      'City.state_id'=&gt;$this-&gt;data['Student']['state_id']
                                                      ),
                                       'group'=&gt;array('City.name')
                                      )
                                  );//closing parentheses for find('list'...
  
  
      $this-&gt;render('/students/ajax_dropdown');
  }
  
  
  function add(){
  
  
      if (!empty($this-&gt;data)){
          /*var_dump($this-&gt;data);
          die(debug($this-&gt;Student-&gt;validationErrors)); */
          $student=$this-&gt;Student-&gt;saveAll($this-&gt;data,array('validate'=&gt;'first'));
          if (!empty($student))
             {
              $this-&gt;Session-&gt;setFlash('Your child\'s admission has been received. We will send you an email shortly.');
                      $this-&gt;redirect(array('controller'=&gt;'pages', 'action'=&gt;'home'));
  
              }
  
  
      } //for if (!empty....
  
       $states=$this-&gt;Student-&gt;State-&gt;find('list');
  
      $cities=array();
        $this-&gt;set(compact('states','cities'));
  
  }//end function
  </code></pre>
  
  <p>}
  ?></p>
  
  <p>merry_parents_controller.php</p>
  
  <pre><code>&lt;?php
   class MerryParentsController extends AppController{
  
  var $name='MerryParents';
  
  
   }
   ?&gt;
  </code></pre>
  
  <p>add.ctp</p>
  
  <pre><code>  &lt;?php
   echo $javascript-&gt;link('prototype',false); 
  
  echo $form-&gt;create('Student');
  echo '&lt;fieldset&gt;';
  echo '&lt;legend&gt;Student Information&lt;/legend&gt;';
  echo $form-&gt;input('Student.name');
  
  $options = array('Male'=&gt;'Male','Female'=&gt;'Female');
  $attributes = array('value'=&gt;'Male');
  echo $form-&gt;radio('Student.gender',$options,$attributes);
  
  echo $form-&gt;input('Student.dob', array('label'=&gt;'Date of Birth',
                  'dateFormat'=&gt;'DMY', 
                  'empty'=&gt;true,
                  'timeFormat' =&gt; '', 
              'minYear' =&gt; ( 
                      date('Y') - 5 
              ), 
              'maxYear' =&gt; ( 
                      date('Y') - 2 
              ) 
              ));
  echo $form-&gt;input('Student.class_id', 
          array(
          'label'=&gt;'Enquiry Class for',
          'empty'=&gt;'Choose one',
  'options'=&gt;array('1'=&gt;'Playgroup','2'=&gt;'Nursery','3'=&gt;'LKG', '4'=&gt;'UKG')
          )
          );
  
  echo '&lt;/fieldset&gt;';
  
  echo '&lt;fieldset&gt;';
  echo '&lt;legend&gt;Parent Information&lt;/legend&gt;';
  //echo $form-&gt;input('Student.parent_id', array('type'=&gt;'hidden'));
  echo $form-&gt;input('MerryParent.initial', 
  array('empty'=&gt;true,
  'options'=&gt;array('Dr'=&gt;'Dr', 
                  'Mr'=&gt;'Mr', 
                  'Mrs'=&gt;'Mrs', 
                  'Ms'=&gt;'Ms')
  )
  );
  echo $form-&gt;input('MerryParent.name', array('label'=&gt;'Parent/Guardian Name'));
  echo $form-&gt;input('MerryParent.email');
  echo $form-&gt;input('MerryParent.landline');
  echo $form-&gt;input('MerryParent.mobile');
  echo $form-&gt;input('MerryParent.address');
        echo $form-&gt;input('Student.state_id');
   echo $form-&gt;input('Student.city_id');
        echo $form-&gt;input('MerryParent.postal_code');
  
        $options = array('url' =&gt; 'getcities', 'update' =&gt; 'StudentCityId');
    echo $ajax-&gt;observeField('StudentStateId', $options); //observes the drop down 
      changes in state id and makes an xmlHttpRequest when its contents have changed.
  
  
      echo '&lt;/fieldset&gt;';
  
  echo $form-&gt;end('Submit');
      ?&gt;
  </code></pre>
  
  <p>ajax_dropdown.ctp</p>
  
  <pre><code>     &lt;?php foreach($options AS $k=&gt;$v) : ?&gt;
        &lt;option value="&lt;?php echo $k; ?&gt;"&gt;&lt;?php echo $v; ?&gt;&lt;/option&gt;
       &lt;?php endforeach; ?&gt;
  </code></pre>