Friday, January 28, 2011

state and city drop down with ajax

hi,
i m working on one project.
in that at one form i am trying to get two drop down one is foe state
and second is for city. i have two table one is for state and second
is for city
by ajax i want to make the options of city corresponding to that state
selected in first drop down.
till now i have tried so far

this is my controller "selects_controller.php"

<?php
class SelectsController extends AppController {

var $name = 'Selects';

function add() {
var $helpers =
array('Html','Form','Ajax','Javascript');
var $components = array('RequestHandler');


$states = $this->Select->State->find('list');
$cities = $this->Select->City->find('list');
$this->set(compact('states', 'cities'));
}

function update_city_select() {
if(!empty($this->data['Select']['State_code'])) {
$options = $this->requestAction('/cities/getlist/'.$this-
>data['Select']['state_code']);
$this->set('options',$options);
}
}

}
?>

this is view "add.ctp"

<div class="Select form">
<?php echo $form->create('Select');?>
<fieldset>
<legend><?php __('Select City');?></legend>
<?php
echo $form-
>select('state_code',array($states ),null,array('id'=>'states'),false);
?><br /><br /><?php
echo $form->select('id',array(),null,array('id'=>'cities'),false);

?>
</fieldset>

</div>

now can any one suggest me what changes should i make in to get the
ajax featured drop down. suggest me the model also,
please help me as early as possible.

best regards

andy

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: