Thanks everyone for all your help.
I found some code that is using Java script and although it's not fully
functional yet I am working on it. If anyone is interested here it is:
<?php require_once("util.php"); /*file holding DB info*/
global $db;
$db = mysql_connect(DBSERVERHOST, DBUSERNAME, DBPASSWORD);
if (!$db)
{
echo "Unable to connect to DB".mysql_error();
exit;
}
$selecteddb = mysql_select_db(DBNAME, $db);
if (!$selecteddb)
{
echo "Unable to select DBNAME:" .mysql_error();
exit;
}
?>
<html>
<head>
<title>.: Combobox :.</title>
<style type="text/css">
<!--
select {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 7pt;
font-style: normal;
font-weight: bold;
color: #000000;
background-color: #FFFFFF;
height: 16px;
width: 300px;
border: 1px solid #000000;
}
#left {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 7pt;
font-style: normal;
font-weight: bold;
color: #000000;
background-color: #FFFFFF;
text-align: right;
vertical-align: middle;
height: 16px;
width: 150px;
}
#right {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 7pt;
font-style: normal;
font-weight: bold;
color: #000000;
background-color: #FFFFFF;
text-align: right;
vertical-align: middle;
height: 16px;
width: 300px;
}
-->
</style>
<Script Language="JavaScript">
function getStates(what) {
if (what.selectedIndex != '') {
var country = what.value;
document.location=('combobox.php?cSel=' + country);
}
}
function getDistrict(what) {
if (what.selectedIndex != '') {
var country = document.myForm.cSelect.selectedIndex;
var state = what.value;
document.location=('combobox.php?cSel=' + country + '&sSel=' +
state);
}
}
function getCity(what) {
if (what.selectedIndex != '') {
var state = document.myForm.sSelect.selectedIndex;
var district = what.value;
document.location=('combobox.php?cSel=' + country + '&sSel=' + state
+ '&dSel=' + district);
}
}
</script>
</head>
<body>
<form name="myForm" method="post" action="">
<table width="450" align="center" cellpadding="1" cellspacing="1">
<tr>
<td id="left">Select your Country:</td>
<td id="right">
<select name="cSelect" onChange="getStates(this);">
<option value="">please, select your country</option>
<?php
global $db;
// Country Select Box Populated with Values from 'country' table.
$country_qu = mysql_query("SELECT * FROM country ORDER BY country", $db);
while ($country_array = mysql_fetch_array($country_qu)) {
$cNa = $country_array["country"];
$cAb = $country_array["cabbrev"];
// This keeps the COuntry elected after JScript has Refreshed the page.
if ($cSel == $cNa) {
echo "<option value=$cNa Selected>$cNa</option>";
} else {
echo "<option value=$cNa>$cNa</option>";
}
}
?>
</select>
</td>
</tr>
<tr>
<td id="left">Select your State or Province:</td>
<td id="right">
<select name="sSelect" onChange="getDistrict(this);">
<option value="">please, select your state or province</option>
<?php
global $db;
// State Select Box Populated with Values from 'stateprovince' table.
if ($cSel) {
$state_qu = mysql_query("SELECT * FROM stateprovince WHERE
country='$cSel' ORDER BY stateprovince",$db);
if (!$state_qu)
{
echo "Could not successfully run the query" .mysql_error();
exit;
}
$sNum = mysql_num_rows($state_qu);
// I put this IF STATEMENT here incase you ever have citys that are not
in states. Just Countrys.
if ($sNum == "0") {
$ctNoState = "none";
} else {
while ($state_array = mysql_fetch_array($state_qu)) {
$sNa = $state_array["stateprovince"];
$sId = $state_array["pid"];
$sCu = $state_array["country"];
// This keeps the state selected after JScript has Refreshed
the page.
if ($sSel == $sId) {
echo "<option value=$sId Selected>$sNa, $sCu</option>";
} else {
echo "<option value=$sId>$sNa, $sCu</option>";
}
}
}
}
?>
</td>
</tr>
<tr>
<td id="left">Select your District:
</td>
<td id="right">
<select name="dSelect" onChange="getCity(this);">
<option value="">please, select your district</option>
<?php
// District Select Box Populated with Values from 'district' table.
if ($sSel) {
// This is the SQL you should keep if you're gonna delete the IF, ELSE
IF.
$district_sql = "SELECT did,pid,district FROM district WHERE pid='$sSel'
ORDER BY district";
}
if ($district_sql != "") {
$district_qu = mysql_query($district_sql,$db);
while ($district_array = mysql_fetch_array($district_qu)) {
$dNa = $district_array["district"];
$dId = $district_array["did"];
$dPid = $district_array["pid"];
echo "<option value=$dId>$dNa</option>";
}
}
?>
</select>
</td>
</tr>
<tr>
<td id="left">Select your City:
</td>
<td id="right">
<select name="ctSelect">
<option value="">please, select your city</option>
<?php
// City Select Box Populated with Values from 'city' table.
// If and ELSE IF are if you have citys inside countrys (no states) Just
Delete it if its not needed.
if ($dSel) {
// This is the SQL you should keep if you're gonna delete the IF, ELSE
IF.
$city_sql = "SELECT city,cityid, did FROM city WHERE did=$dSel ORDER BY
city";
}
//else if ($cSel && ($ctNoState == "none")) {
// $city_sql = "SELECT city,cityid, did FROM city WHERE countryid=$cSel
ORDER BY city_name";
//}
if ($city_sql != "") {
$city_qu = mysql_query($city_sql);
while ($city_array = mysql_fetch_array($city_qu)) {
$ctNa = $city_array["city"];
$ctId = $city_array["cityid"];
echo "<option value=$ctId>$ctNa</option>";
}
}
?>
</select>
</td>
</tr>
<tr>
<td id="left"></td>
<td id="right"></td>
</tr>
</table>
</form>
</body>
</html>
-----Original Message-----
From: Neil Smith [MVP, Digital media] [mailto:[EMAIL PROTECTED]
Sent: Thursday, May 13, 2004 4:16 AM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: Re:RE: [PHP-DB] question on <select>
That *should* read :
document.fcountry.newcountry.value =
document.fcountry.country[document.fcountry.country.selectedIndex].value;
Skip the 'options' object - I'm surprised you're not getting a javascript
error, maybe you have error reporting turned off in your browser ? In any
case, always 'alert' that value when you create it, so you know what you're
actually submitting during testing.
At 04:06 13/05/2004 +0000, you wrote:
>From: "hengameh" <[EMAIL PROTECTED]>
>To: <[EMAIL PROTECTED]>,
> <[EMAIL PROTECTED]>
>Date: Wed, 12 May 2004 12:22:20 -0400
>MIME-Version: 1.0
>Content-Type: text/plain;
> charset="us-ascii"
>Content-Transfer-Encoding: 7bit
>Message-ID: <[EMAIL PROTECTED]>
>Subject: RE: [PHP-DB] question on <select>
>
><!--
>function changeMenu()
> {
> document.fcountry.newcountry.value =
>document.fcountry.country.options[document.fcountry.country.selectedIndex].
v
>alue;
> }
>-->
></script>
========================================================
CaptionKit http://www.captionkit.com : Production tools
for accessible subtitled internet media, transcripts
and searchable video. Supports Real Player, Quicktime
and Windows Media Player.
VideoChat with friends online, get Freshly Toasted every
day at http://www.fresh-toast.net : NetMeeting solutions
for a connected world.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php