Dynamic Dropdown for Country and City List
/*
- Function to return the Country list as an array
- The array can be generated from a database resultset
*/
function getCountryList()
{
// Country List array
$countryList = array (
'1' => 'Bangladesh',
'2' => 'USA',
'3' => 'UK'
);
return $countryList;
}
/*
- Function to return the City list as an array
- Country ID is used to generate the city list
*/
function getCityList($countryId)
{
// City list array
// First key of the array is the Country ID, which holds an array of City list
$cityList = array (
'1' => array ('Dhaka', 'Chittagong', 'What else'),
'3' => array ('London', 'Cannot Remember'),
'2' => array ('Washington', 'N.Y.', 'etc')
);
return $cityList[$countryId];
}
?>
http://blog.roodo.com/taikobo0/archives/8671037.html
|