[IMG]http://i36.tinypic.com/11rus5g.jpg[/IMG]
So far i have a database with all data in it.
I have the 1st text field where the user enters their postcode and then the page reloads populating the drop down menu with the corresponding suburbs.
Next what i want is after a suburb has been selected in the list, the page reloads again and the corresponding city, state and country is displayed in the other 3 text fields.
How can i get the query to execute and fill in the last 3 fields after a suburb in the drop list has been selected???????
<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
<title>Postcode and Address Selection Test</title>
<SCRIPT language=JavaScript>
function reload(form)
{
var val=form.postcode.value;
self.location='dd.php?postcode=' + val ;
}
</script>
</head>
<body>
<?
@$postcode=$_GET['postcode']; // Use this line or below line if register_global is off
@$city=$_GET['city'];
@$state=$_GET['state'];
@$country=$_GET['country'];
$city = 'not_complete';
$state = 'not_complete';
$country = 'not_complete';
/////// for suburb drop down list we will check if postcode is entered else we will display all the suburbs/////
if(isset($postcode) and strlen($postcode) > 0){
$query=mysql_query("SELECT DISTINCT suburb FROM post2 where postcode=$postcode order by suburb"); //Table called POST2
}else{$query2=mysql_query("SELECT DISTINCT suburb FROM post order by suburb"); }
////////// end of query for second subcategory drop down list box /////////////////////////////////////////////
echo "<form method=post name=f1 action='dd-check.php'>";//Goes to dd-check to check posted variables
//Page Reloads after 4 digits are entered///<<<<--------------POSTCODE FIELD-------<<<<<<<<<<<<<<
echo "Postcode: <input name='postcode' type=text onkeyup=\"if(this.value.length>3)reload(this.form);else return false;\" value=$postcode>";
echo"<input value='Load Suburbs' type='button' onclick=\"reload(this.form)\" > Click to Load Suburbs for this Postcode.";
//////////////////Starting of suburb drop downlist///<<<<--------------SUBURB-------<<<<<<<<<<<<<
echo"<br><br>";
echo"Suburb: ";
echo "<select name='suburb'><option value=''>Select Suburb</option>"; // onchange=\"reload(this.form)\"
while($pop = mysql_fetch_array($query)) {
echo "<option value='$pop[suburb]'>$pop[suburb]</option>";
}//else{
//echo "<option value='$pop[suburb]'>$pop[suburb]</option>";
//}
echo "</select>";
////////////////// This will end the suburb drop down list ///////////
///////////////Execute this when suburb is selected////////////////////<<-----NEED TO FIX-------<<<<<<
//if(isset($suburb) and strlen($suburb) > 0){
$query_city=mysql_query("SELECT city FROM post2 where postcode=$postcode AND $suburb=$suburb");
//}else{
//$city = 'not_complete1';
//}
$query_state=mysql_query("SELECT state FROM post2 where postcode=$postcode AND $suburb=$suburb");
$query_country=mysql_query("SELECT country FROM post2 where postcode=$postcode AND $suburb=$suburb");
echo "<br>";
echo "<br>";
echo "City: <input name='city' type=text value=$city>";
echo "<br>";
echo "<br>";
echo "State: <input name='state' type=text value=$state>";
echo "<br>";
echo "<br>";
echo "Country: <input name='country' type=text value=$country>";
//-----------------------------------------------
echo "<br><br><input type=submit value=Submit>";
echo "</form>";
?>
</body>
</html>
Thankyou,
Billy