greenday Posted August 30, 2007 Share Posted August 30, 2007 Hi I have three dependant drop down menus, which gets thier values from a database on refresh, dependant on the selection of the menu above. How can i keep the selected values? Because on refresh, the menus goes back to the first selection. Example can be seen at: http://peugeot.websitewelcome.com/~perfect/Untitled-1.php At the momment, only Auckland > Auckland City works. code: <?php require_once('Connections/admin.php'); ?> <?php mysql_select_db($database_admin, $admin); $query_regions = "SELECT * FROM regions ORDER BY regions.regionName ASC"; $regions = mysql_query($query_regions, $admin) or die(mysql_error()); $row_regions = mysql_fetch_assoc($regions); $totalRows_regions = mysql_num_rows($regions); mysql_select_db($database_admin, $admin); $query_districts = "SELECT * FROM districts WHERE districts.regionID = '$regions_id' ORDER BY districts.districtName ASC"; $districts = mysql_query($query_districts, $admin) or die(mysql_error()); $row_districts = mysql_fetch_assoc($districts); $totalRows_districts = mysql_num_rows($districts); mysql_select_db($database_admin, $admin); $query_suburbs = "SELECT * FROM suburbs WHERE suburbs.districtID = '$districts_id' ORDER BY suburbs.suburbName ASC"; $suburbs = mysql_query($query_suburbs, $admin) or die(mysql_error()); $row_suburbs = mysql_fetch_assoc($suburbs); $totalRows_suburbs = mysql_num_rows($suburbs); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Untitled Document</title> </head> <body> <form action="Untitled-1.php" method="get"> <table width="285" border="0" cellspacing="0" cellpadding="2"> <tr class="formtext"> <td> <select name="regions_id" onchange="this.form.submit()" class="searchformlong"> <option value="">All Regions</option> <?php do { ?> <option value="<?php echo $row_regions['regionID']?>"><?php echo $row_regions['regionName']?></option> <?php } while ($row_regions = mysql_fetch_assoc($regions)); $rows = mysql_num_rows($regions); if($rows > 0) { mysql_data_seek($regions, 0); $row_regions = mysql_fetch_assoc($regions); } ?> </select></td> </tr> <tr class="formtext"> <td><select name="districts_id" class="searchformlong" onchange="this.form.submit()"> <option value="">All Districts</option> <?php do { ?> <option value="<?php echo $row_districts['districtID']?>"><?php echo $row_districts['districtName']?></option> <?php } while ($row_districts = mysql_fetch_assoc($districts)); $rows = mysql_num_rows($districts); if($rows > 0) { mysql_data_seek($districts, 0); $row_districts = mysql_fetch_assoc($districts); } ?> </select></td> </tr> <tr class="formtext"> <td><select name="suburbs_id" class="searchformlong"> <option value="">All Suburbs</option> <?php do { ?> <option value="<?php echo $row_suburbs['suburbID']?>"><?php echo $row_suburbs['suburbName']?></option> <?php } while ($row_suburbs = mysql_fetch_assoc($suburbs)); $rows = mysql_num_rows($suburbs); if($rows > 0) { mysql_data_seek($suburbs, 0); $row_suburbs = mysql_fetch_assoc($suburbs); } ?> </select></td> </tr> </table> </form> Region = <?php echo $regions_id; ?><br> District = <?php echo $districts_id; ?><br> Suburb = <?php echo $suburbs_id; ?> </body> </html> <?php mysql_free_result($regions); mysql_free_result($districts); mysql_free_result($suburbs); ?> Quote Link to comment https://forums.phpfreaks.com/topic/67359-keeping-menu-selections-on-refresh/ Share on other sites More sharing options...
greenday Posted August 31, 2007 Author Share Posted August 31, 2007 -- bump -- Quote Link to comment https://forums.phpfreaks.com/topic/67359-keeping-menu-selections-on-refresh/#findComment-338378 Share on other sites More sharing options...
Ken2k7 Posted August 31, 2007 Share Posted August 31, 2007 3 things you can do: 1. use AJAX 2. use Javascript 3. use complete PHP For 3, you'll have to make a form and have the user submit the dropdown value, then display whatever afterwards. Quote Link to comment https://forums.phpfreaks.com/topic/67359-keeping-menu-selections-on-refresh/#findComment-338430 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.