<html>
<head>
<title></title>
</head>
<body>
<SCRIPT language=JavaScript>
function reload(form)
{
// Setting the variable with the value of selected country's ID
var val=populate.countries.options[populate.countries.options.selectedIndex].value;
self.location='experim.php?countryId=' + val;
var val2=val+'&cityID='+populate.cities.options[populate.cities.options.selectedIndex].value;
self.location='experim.php?countryId=' + val2;
var val3=val2+'&groupID='+populate.groups.options[populate.groups.options.selectedIndex].value;
self.location='experim.php?countryId=' + val3;
}
JOptionPane.showMessageDialog(frame, "Eggs aren't supposed to be green.");
</script>
<?php
function getCountryList()
{ $countries = array (
'1' => 'Bangladesh',
'2' => 'USA',
'3' => 'UK'
);
return $countries;
}
function getCityList($countryId)
{
// City list array
// First key of the array is the Country ID, which holds an array of City list
$cities = array (
'Bangladesh' => array ('Dhaka', 'Chittagong', 'What else'),
'UK' => array ('London', 'Cannot Remember'),
'USA' => array ('Washington', 'N.Y.', 'etc')
);
return $cities[$countryId];
}
function getGroupList($cityID)
{
$groups = array (
'etc' => array ('aka', 'Chg', ' else'),
'Washington' => array ('ndon', 'Cnnot member'),
'N.Y.' => array ('ashington', 'N.Y.', 'et')
//list of groups
);
return $groups[$cityID];
}
?>
<form action="experim.php" name="populate">
<?
// Retrieving the country list
$countries = getCountryList();
// Setting the variable if the country is selected for its city list
@$countryId = $_GET['countryId'];
@$cityID = $_GET['cityID'];
// Retrieving the city list if a country is selected
$cities = ($countryId) ? getCityList($countryId) : null;
$groups = ($cityID) ? getGroupList($cityID) : null;
if (!empty($countries))
{
// Generating the country drop down menu
echo "<select onChange='reload(this.form)' name='countries'>";
foreach ($countries as $value)
{
echo "<option value='$value'";
if ($countryId == $value)
echo "selected";
echo ">$value</option>";
}
echo "</select>";
}
if (!empty($cities))
{
// Generating the city drop down menu if a country is selected
echo "<select onChange='reload(this.form)' name='cities'>";
foreach ($cities as $value)
{
echo "<option value='$value'";
if ($cityID == $value)
echo "selected";
echo ">$value</option>";
}
echo "</select>";
}
if (!empty($groups))
{
// Generating the city drop down menu if a country is selected
echo "<select onChange='reload(this.form)' name='groups'>";
foreach ($groups as $value)
{
echo "<option value='$value'";
if ($groupID == $value)
echo "selected";
echo ">$value</option>";
}
echo "</select>";
}
if (!empty($groups))
{
// Generating the city drop down menu if a country is selected
echo "<select name='groups'>";
foreach ($groups as $key=>$value)
{
echo "<option value='$key'>$value</option>";
}
echo "</select>";
}
?>
</body>
</html>