Hey,
My code i pretty messed up at the moment but i was hoping someone could help me change it so that when the form is reloaded the 2nd time round that the value in the drop down menu that's selected stays after the reload.
<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
<title>Postcode and Address Selection Test</title>
<SCRIPT language=JavaScript> //Reloads the page
function reload(form)
{
var val=form.postcode.value;
self.location='dd.php?postcode=' + val;
}
function reload2(form)
{
var val=form.postcode.value;
var val2=form.suburb.options[form.suburb.options.selectedIndex].value;
self.location='dd.php?postcode=' + val + '&suburb=' + val2;
}
</script>
</head>
<body>
<?
@$postcode=$_GET['postcode']; // Use this line or below line if register_global is off
@$suburb=$_GET['suburb'];
/////// 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
}
////////// 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' onchange=\"reload2(this.form)\"><option value='$suburb'>Select Suburb</option>"; // onchange=\"reload(this.form)\"
while($pop = mysql_fetch_array($query)) {
if($pop['postcode']==@$suburb){
echo "<option value='$suburb'>$pop[suburb]</option>";
}else{
echo "<option selected value='$suburb'>$pop[suburb]</option>";}
}
echo "</select>";
////////////////// This will end the suburb drop down list ///////////
//-----------------------------------------------
echo "<br><br><input type=submit value=Submit>";
echo "</form>";
?>
</body>
Thankyou,
Billy