Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Country and State Site Registration Form

Status
Not open for further replies.

WebStuck

Programmer
Joined
Apr 12, 2003
Messages
79
Location
US
Hi,

I have registration form that contains country and state drop down fields. I use PHP to access a MySQL database to bring up a list of countries for the country drop down field. However, I only want to display a state drop down field if a country with states such as the United States is selected. Then if the state field is displayed, I want it to bring up the relevant states to form the drop down list. I have already asked this question in the PHP area but was told that it sounded more like a javascript question.

So far, I have it where PHP will bring up a list of countries then when a country is selected, javascript will pop up an alert with the name of the country selected. I'm not sure what the next step is to get the corresponding country's states to show up if a country with states is selected.

Here is my code so far:

<html>
<head>
<script language="JavaScript" type="text/javascript">
<!--
function DisplayStatesOrCities(member_country)
{
alert(member_country.value)
}
//-->
</script>
</head>
<body>
<p align="center">
<form method="POST" action=" PROCESSING URL">
Country:
<select name="member_country" onchange="DisplayStatesOrCities(this)">
<option>
</option>
<?php
$link = mysql_connect('localhost', 'username', 'password');
if (!$link)
{
die('Not connected: ' . mysql_error());
}

// MAKE DB THE CURRENT DB
$db_selected = mysql_select_db('db', $link);
if (!$db_selected)
{
die('Can\'t switch to database: ' . mysql_error());
}

$query = "SELECT DISTINCT LOCATION_COUNTRY FROM LOCATION";

$result = mysql_query($query);
if (!$result)
{
die('Invalid query: ' . mysql_error());
}

while ($row = mysql_fetch_array($result))
{
$country = stripslashes($row["LOCATION_COUNTRY"]);
print "<option value=\"$country\">" . $country . "</option>";
}

mysql_free_result($result);
?>
</select><br>
State:
<input type="text" name="member_state" size="20"><br>
City:
<input type="text" name="member_city" size="20"><br>
</form>
</p>
</body>
</html>

Thanks!
Ben
 
I left off:

<input type="submit" value="Submit" name="submit">

before the </form> tag in my previous post.

- Ben
 
Hi,

I am really surprised that I have not received a response to my question yet. I have used this board numerous times and until now, have always got quick responses. Does my posted question make sense?

Thanks!
Ben Cunningham
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top