I have 2 selecttag, one which allows me to select the projects and then it will update the related subjects in the second selecttag.
I've been using this tutorial, http://www.devmoz.com/blog/2007/04/04/cakephp-update-a-select-box-using-ajax/ but I'm having problem populating the second selecttag. In my view, I have the following codes: <code> <?php echo $html->selectTag('Project/id',$projectNames, null, array ('onchange' => 'setSubjects()', 'id' => 'ProjectId', 'value' => '')); ? > <?php echo $html->selectTag('Subject/id', array(), null, array ('id' => 'SubjectId')); $options = array('url' => '/radar_verbatims/ajax_calls', 'update' => 'SubjectId', 'frequency' => '0.2'); echo $ajax->observeField('ProjectId', $options); ?> </code> In my controller I have this function: <code> function ajax_calls() { $this->layout = 'ajax'; $project_id = $this->data['Project']['id']; $this->set('project', $project_id); $sql = "SELECT ProjectsSubjects.name FROM projects_subjects AS ProjectsSubjects WHERE ProjectsSubjects.project_id = $project_id"; $q = mysql_query($sql); $subjectNames = array(); while($row = mysql_fetch_array($q)) { //$subjectNames[$row['name']] = $row['name']; $subjectNames[] .= $row['name']; } $this->set('subjectNames', $subjectNames); </code> and lastly I have another view, named ajax_calls.thtml which this code <script type = "text/javascript"> document.getElementById('test').innerHTML = <?php print var_dump ($subjectNames); ?>; </script> I'm quite confuse with this whole thing. As much as I found out, the observe field will observe the ProjectId selecttag and once there are changes made to the selecttag, it will trigger the function ajax_calls. I managed to set the array $subjectNames with all the data I require, but it didn't update the SubjectId selecttag for some reason. Glad if someone could point me out my mistake. The application is using cake 1.1 if I'm not mistaken. tienzyee --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---