My values from my text boxes go blank when i use these dynamic drop downs I found from another site. The drop downs work great but its kinda annoying that the user has to retype the information whenever the drop downs used. Is there a way I can save the content of the text boxes when the page reloads? 😕
<head>
<SCRIPT language=JavaScript>
function reload(form)
{
var val=form.cat.options[form.cat.options.selectedIndex].value;
self.location='register.php?cat=' + val ;
}
function reload3(form)
{
var val=form.cat.options[form.cat.options.selectedIndex].value;
var val2=form.subcat.options[form.subcat.options.selectedIndex].value;
var val3=form.subcat3.options[form.subcat3.options.selectedIndex].value;
self.location='register.php?cat=' + val + '&cat3=' + val2 + '&cat5' + val3 ;
}
</script>
</head>
<?
include "conn.inc.php";
if (isset($_POST[ 'submit' ]) && $_POST[ 'submit' ] == "Register") {
if ($_POST['postal'] != "" &&
$_POST['lat'] != "" &&
$_POST['long'] != "" &&
$_POST['postal'] != "") {
$query = "SELECT postal_code FROM postal " .
"WHERE postal_code = '" . $_POST['postal'] . "';";
$result = mysql_query($query)
or die(mysql_error());
if (mysql_num_rows($result) != 0) {
?>
<font color="#FF0000"><b>The Postal Code, <?php echo $_POST['postal']; ?>, is already in the database.</b></font>
<form action="pc.php" method="post"><br>
<?php
$quer2=mysql_query("SELECT DISTINCT country,country_id FROM country order by country");
$cat=$HTTP_GET_VARS['cat'];
if(isset($cat) and strlen($cat) > 0){
$quer=mysql_query("SELECT DISTINCT province,province_id FROM province where country_id=$cat order by province");
}else{$quer=mysql_query("SELECT DISTINCT province,province_id FROM province order by province"); }
$cat3=$HTTP_GET_VARS['cat3'];
if(isset($cat3) and strlen($cat3) > 0){
$quer3=mysql_query("SELECT DISTINCT city, city_id FROM city where province_id=$cat3 order by city");
}else{$quer3=mysql_query("SELECT DISTINCT city, city_id FROM city order by city"); }
echo "<form method=post name=f1 action='postal_code.php'>";
echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select one</option>";
while($noticia2 = mysql_fetch_array($quer2)) {
if($noticia2['country_id']==@$cat){echo "<option selected value='$noticia2[country_id]'>$noticia2[country]</option>"."<BR>";}
else{echo "<option value='$noticia2[country_id]'>$noticia2[country]</option>";}
}
echo "</select>";
echo "<select name='subcat' onchange=\"reload3(this.form)\"><option value=''>Select one</option>";
while($noticia = mysql_fetch_array($quer)) {
if($noticia['province_id']==@$cat3){echo "<option selected value='$noticia[province_id]'>$noticia[province]</option>"."<BR>";}
else{echo "<option value='$noticia[province_id]'>$noticia[province]</option>";}
}
echo "</select>";
echo "<select name='subcat3'<option value=''>Select one</option>";
while($noticia = mysql_fetch_array($quer3)) {
if($noticia['city_id']==@$cat3){echo "<option selected value='$noticia[city_id]'>$noticia[city]</option>"."<BR>";}
else{echo "<option value='$noticia[city_id]'>$noticia[city]</option>";}
}
echo "</select>";
?>
<br>
Latitude:
<input type="text" name="lat"> <br>
Longtitude:
<input type="text" name="long"> <br>
Postal Code:
<input type="text" name="postal"> <br>
<input type="submit" name="submit" value="Register">
</p>
</p>
<a href="logged_admin.php">Click Here to return to Admin Menu</a><br>
</form>
<?php
} else {
$query = "INSERT INTO postal
(city_id, postal_code, latitude, longitude)
VALUES
('" . $_POST['subcat3'] . "', '" . $_POST['postal'] . "', '" . $_POST['lat'] . "', '". $_POST['long'] . "');";
$result = mysql_query($query)
or die(mysql_error());
echo "(Click here to continue, " .
"<a href=\"pc.php\">click here</a>)";
}
} else {
?>
<p> <font color="#FF0000"><b>There can be no blank entrees.</b></font>
<form action="pc.php" method="post"><br>
<?php
$quer2=mysql_query("SELECT DISTINCT country,country_id FROM country order by country");
$cat=$HTTP_GET_VARS['cat'];
if(isset($cat) and strlen($cat) > 0){
$quer=mysql_query("SELECT DISTINCT province,province_id FROM province where country_id=$cat order by province");
}else{$quer=mysql_query("SELECT DISTINCT province,province_id FROM province order by province"); }
$cat3=$HTTP_GET_VARS['cat3'];
if(isset($cat3) and strlen($cat3) > 0){
$quer3=mysql_query("SELECT DISTINCT city, city_id FROM city where province_id=$cat3 order by city");
}else{$quer3=mysql_query("SELECT DISTINCT city, city_id FROM city order by city"); }
echo "<form method=post name=f1 action='postal_code.php'>";
echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select one</option>";
while($noticia2 = mysql_fetch_array($quer2)) {
if($noticia2['country_id']==@$cat){echo "<option selected value='$noticia2[country_id]'>$noticia2[country]</option>"."<BR>";}
else{echo "<option value='$noticia2[country_id]'>$noticia2[country]</option>";}
}
echo "</select>";
echo "<select name='subcat' onchange=\"reload3(this.form)\"><option value=''>Select one</option>";
while($noticia = mysql_fetch_array($quer)) {
if($noticia['province_id']==@$cat3){echo "<option selected value='$noticia[province_id]'>$noticia[province]</option>"."<BR>";}
else{echo "<option value='$noticia[province_id]'>$noticia[province]</option>";}
}
echo "</select>";
echo "<select name='subcat3'<option value=''>Select one</option>";
while($noticia = mysql_fetch_array($quer3)) {
if($noticia['city_id']==@$cat3){echo "<option selected value='$noticia[city_id]'>$noticia[city]</option>"."<BR>";}
else{echo "<option value='$noticia[city_id]'>$noticia[city]</option>";}
}
echo "</select>";
?>
<br>
Latitude:
<input type="text" name="lat"> <br>
Longtitude:
<input type="text" name="long"> <br>
Postal Code:
<input type="text" name="postal"> <br>
<input type="submit" name="submit" value="Register">
</p>
</p>
<a href="logged_admin.php">Click Here to return to Admin Menu</a><br>
</form>
<?php
}
} else {
?>
<p> <font color="#FF0000"><b>Please Enter a Province.</b></font>
<form action="pc.php" method="post"><br>
<?php
$quer2=mysql_query("SELECT DISTINCT country,country_id FROM country order by country");
$cat=$HTTP_GET_VARS['cat'];
if(isset($cat) and strlen($cat) > 0){
$quer=mysql_query("SELECT DISTINCT province,province_id FROM province where country_id=$cat order by province");
}else{$quer=mysql_query("SELECT DISTINCT province,province_id FROM province order by province"); }
$cat3=$HTTP_GET_VARS['cat3'];
if(isset($cat3) and strlen($cat3) > 0){
$quer3=mysql_query("SELECT DISTINCT city, city_id FROM city where province_id=$cat3 order by city");
}else{$quer3=mysql_query("SELECT DISTINCT city, city_id FROM city order by city"); }
echo "<form method=post name=f1 action='postal_code.php'>";
echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select one</option>";
while($noticia2 = mysql_fetch_array($quer2)) {
if($noticia2['country_id']==@$cat){echo "<option selected value='$noticia2[country_id]'>$noticia2[country]</option>"."<BR>";}
else{echo "<option value='$noticia2[country_id]'>$noticia2[country]</option>";}
}
echo "</select>";
echo "<select name='subcat' onchange=\"reload3(this.form)\"><option value=''>Select one</option>";
while($noticia = mysql_fetch_array($quer)) {
if($noticia['province_id']==@$cat3){echo "<option selected value='$noticia[province_id]'>$noticia[province]</option>"."<BR>";}
else{echo "<option value='$noticia[province_id]'>$noticia[province]</option>";}
}
echo "</select>";
echo "<select name='subcat3'<option value=''>Select one</option>";
while($noticia = mysql_fetch_array($quer3)) {
if($noticia['city_id']==@$cat3){echo "<option selected value='$noticia[city_id]'>$noticia[city]</option>"."<BR>";}
else{echo "<option value='$noticia[city_id]'>$noticia[city]</option>";}
}
echo "</select>";
?>
<br>
Latitude:
<input type="text" name="lat"> <br>
Longtitude:
<input type="text" name="long"> <br>
Postal Code:
<input type="text" name="postal"> <br>
<input type="submit" name="submit" value="Register">
</p>
</p>
<a href="logged_admin.php">Click Here to return to Admin Menu</a><br>
</form>
<?php
}
?>
</center>
</body>
Thanks for the help. 🙂