I am trying to use a select box to update another select box using
ajax.  I have two tables: locations and nodes, and Locations hasMany
Nodes and Nodes belongsTo Locations.  I want a locations select box to
update the nodes select box with all the nodes that are at that
location.
I've been to multiple forums with great tutorials explaining how this
works, but I follow their directions exactly and it never works.
I am brand new to any type of AJAX development, and I have only been
developing with CakePHP for a couple weeks now.

Here is the code:

In my controller:
----------------------------------------------------------------------------------------------------------------------------
function update_select() {
        if(!empty($this->data)) {
                $locationId = $this->data['Location']['id'];
                $options = $this->Iface->Node->find('list', 
array('conditions'=>array
('Node.location_id'=>$locationId)));
                $this->set('options', $options);
                $this->render('update_select');
        }
}
----------------------------------------------------------------------------------------------------------------------------
In my view:
----------------------------------------------------------------------------------------------------------------------------
<?php echo $form->input('Location.id', array
('type'=>'select','options'=>$locations, 'id' => 'LocationId',
'label'=>'Location')); ?>
<?php echo $form->input('Node.id', array('type'=>'select', 'options'=>
$nodes,'id' => 'NodeId', 'label'=>'Node')); ?>
----------------------------------------------------------------------------------------------------------------------------
In my update_select.ctp:
----------------------------------------------------------------------------------------------------------------------------
<?php foreach ($options as $i => $option): ?>
        <option value="<?php echo $i; ?>"><?php echo $option; ?></option>
<?php endforeach; ?>
----------------------------------------------------------------------------------------------------------------------------

(I have Ajax and Javascript helpers, RequestHandler component, and
prototype all defined)

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to