20 Apr
Populate triple drop down list from database using Ajax and PHP Symfony
I'm doing this by first populating only the country dropdown in the form class, leaving states and cities empty, and using a jquery .change() function to fire off an ajax request to other symfony actions that return states/cities.
Your city ajax action might look something like this:
Your Jquery function might look something like this:
Add frills, loaders, disabled selects, tighter validation, etc ... as needed.
Your city ajax action might look something like this:
if ($request->isXmlHttpRequest()) {
$state_id = (int)$request->getParameter('state_id');
if($state_id) {
$q = Doctrine_Query::create()
->select('c.city_id, c.city_name')
->from('City c')
->where('c.state_id = ?', $state_id);
$cities = $q->execute(array(), Doctrine_Core::HYDRATE_NONE);
$output = '<option value="">Please select</option>';
foreach($cities as $c) $output .= '<option value="'.$c[0].'">'.$c[1].'</option>';
return $this->renderText($output);
}
}
Your Jquery function might look something like this:
$(".state-dropdown").change(function() {
var url = // your ajax action relative url, pass it however you like
var value = $(this).val();
$.get(url, {state_id: value}, function(output) {
$(".city-dropdown").html(output);
});
});
Add frills, loaders, disabled selects, tighter validation, etc ... as needed.








Blog Detail
Comments (1)
Shahbaz Ahmed Says:
can u give me complete tutorial that how to manage tripple drop down list
thankx