I have the following 'Customer' table in a MySQL database:
CustomerID
CustomerName
Address
City
StateProv
PostalCode
Country
There are numerous customers and I need three drop down
menus that allow the user to select a Country then based
on that country, the next drop down list will list the
states for that country. After a state is selected the
third drop down box will contain a list of the cities
for that state. There will be a button at the bottom of
the lists (Display List) this sends these choices to a
new page that displays only the customers for the country,
state and city chosen. I need for all of the data to come from
the database, no external arrays.
I was told that JavaScript needed to be added to the
program. Some one who is supposed to know about JavaScript
gave me the following, it doesn't work right. The first box
does list the countries, but nothing happens with the
onChange. I don't have enough experience to even know if
the correct things are being passed to the database.
Can anyone tell me what needs to be done??
Do I need to take out the PHP? Help, Please, I'm tearing
my hair out!!
Code: Select all
<?php
include('db.php');
mysql_select_db($dbname);
?>
<p>
<FORM name="searchData" method=post action="displayList.php">
<font face="Verdana, Arial, Helvetica, sans-serif" size="4"> <font size="4"> Choose
a Country:
<SELECT NAME="selectCountry" <SCRIPT LANGUAGE="JavaScript"> onChange="document.open('findCountry.php?Country=document.searchData.selectCountry')" </SCRIPT> >
<?
$cname = mysql_query("SELECT DISTINCT (Country) FROM `Customer` ORDER BY Country ASC ");
while($row_cname = mysql_fetch_array($cname))
{
if($row_cnameї0] == $row_cnameїCountry])
{
printf ("<option value==$row_cnameї0] selected> $row_cnameї0]</option> ");
}
}
printf ("<option selected> Select a Country </option> ");
?>
</select>
</font>
<br>
<br>
<font face="Verdana, Arial, Helvetica, sans-serif" size="4"> Choose a State:
<? if (document.searchData.selectCountry !="")
{?>
<select name="selectState" <SCRIPT LANGUAGE="JavaScript"> onChange="document.open('findCountry.php?Country=document.searchData.selectCountry&StateProv=document.searchData.selectState')"</SCRIPT> >
<?
$sname = mysql_query("SELECT DISTINCT (StateProv) FROM `Customer` WHERE Country='document.searchData.selectCountry' ORDER BY StateProv ASC ");
while($row_sname = mysql_fetch_array($sname))
{
if($row_snameї0] == $row_snameїStateProv])
{
printf ("<option value==$row_snameї0] selected> $row_snameї0]</option> ");
}
}
printf ("<option selected> Select a State </option> ");
}?>
</select>
</font>
<br>
<br>
<font face="Verdana, Arial, Helvetica, sans-serif" size="4"> Choose a City:</font>
<? if (document.searchData.selectState !="")
{?>
<select name="selectCity" <SCRIPT LANGUAGE="JavaScript"> onChange="document.open('findCountry.php?Country=document.searchData.selectCountry&StateProv=document.searchData.selectState&City=document.searchData.selectCity')" </SCRIPT> >
<?
$tname = mysql_query("SELECT DISTINCT (City) FROM `Customer` WHERE Country='document.searchData.selectCountry' AND StateProv='document.searchData.selectState' ORDER BY City ASC ");
while($row_tname = mysql_fetch_array($tname))
{
if($row_tnameї0] == $row_tnameїCity])
{
printf ("<option value==$row_tnameї0] selected> $row_tnameї0]</option> ");
}
}
printf ("<option selected> Select a City </option> ");
}?>
</select>
</font>
<div align="center">
<center>
<p> <span style="font-family: Verdana, Arial">
<input type="submit" value="Display List" >
</span></p>
</center>
</div>
</form>