I have put together this drop down code to drill
down from country > state > town.
As a lone php page, it works fine, but when I put
it in block on a drupal page, the countries load, but when I select, say,
Canada, the page refreshes as it should but the United States is always there,
not Canada.
Possibly it's a problem relating to the javascript,
the self.location maybe. I'd appreciate any help with this one.
----------------------------------------------------------------------------------
<?
//connect to database//
include
"connect.php";
//start session//
session_start();
//update
session if country selection
changed//
if(isset($_POST['countryList']))
{
if(isset($_POST['stateList']))
$_SESSION['state_shc'] = $_POST['stateList'];
$stateList =
$_SESSION['state_shc'];
}
?>
<SCRIPT
language=JavaScript>
function reload(form)
{
// Setting the variable
with the value of selected country's ID
var
val=populate.countryList.options[populate.countryList.options.selectedIndex].value;
// Sending the country id in the query string to
retrieve the city list
self.location='index.php?countryId=' + val
;
}
</script>
<?
$query = "SELECT country_shc, country_name
FROM countries ORDER BY country_shc";
$result =
mysql_query($query);
$country_shc =
$_SESSION['country_shc'];
?>
<form name="form1" action=""
method="post">
<select
onChange='form1.submit();' name='countryList'>
<?
while($row =
mysql_fetch_array($result, MYSQL_ASSOC))
{
echo "<option
value='{$row['country_shc']}'";
if
($countryId == $row['country_shc'])
echo
"selected";
echo
">{$row['country_name']}</option>";
}
?>
</select>
</form>
<?
$_SESSION['country_shc'] =
$_POST['countryList'];
$_SESSION['stateId'] =
$_POST['stateList'];
$query = "SELECT state_shc, state_name
FROM states WHERE country_shc =
'$country_shc'";
$result =
mysql_query($query);
?>
<form name="form2" action=""
method="post">
<select
onChange='form2.submit();'
name='stateList'>
<?
while($row = mysql_fetch_array($result,
MYSQL_ASSOC))
{
echo
"<option
value='{$row['state_shc']}'";
if
($stateId ==
$row['state_shc'])
echo "selected";
echo
">{$row['state_name']}</option>";
}
?>
</select>
<input type="hidden"
name="countryList" value="<?=$_SESSION['country_shc'];?>"
/>
</form>
<?
$_SESSION['state_shc'] =
$_POST['stateList'];
$state_shc =
$_SESSION['state_shc'];
$_SESSION['cityId']
= $_POST['cityList'];
$query = "SELECT
city_id, city_name FROM cities WHERE state_shc =
'$state_shc'";
$result =
mysql_query($query);
?>
<select
name='cityList'>
<?
while($row = mysql_fetch_array($result,
MYSQL_ASSOC))
{
echo
"<option
value='{$row['city_shc']}'";
if
($cityId ==
$row['city_shc'])
echo "selected";
echo
">{$row['city_name']}</option>";
}
?>
</select>