I am trying to make three dynamic drop down lists. When I say dynamic I mean when I choose a value from the first one, the second one changes options and when I choose a value from the second one then the third one changes options. But at the end I want the to keep the selected values because I will submit them. For example the first list may be Country, the second one may be City and the third one Postal Code. So once I choose country I want the cities in that country to be visible and again once I choose city I want postal code to be visible, buy I do not want to loose my selections every time because I will submit them at the end. I was able to make it up to two drop down menus and it works perfect, but once I add the third everything is destroyed.
Take a look at my code for the first two menus and if you can help me I will really appreciate it
Expand|Select|Wrap|Line Numbers
- <!doctype html public "-//w3c//dtd html 3.2//en">
- <html>
- <head>
- <title>Multiple drop down list box from plus2net</title>
- <SCRIPT language=JavaScript>
- function reload(form)
- {
- var val=form.cat.options[form.cat.options.selectedIndex].value;
- self.location='dropmenutest.php?cat=' + val ;
- }
- </script>
- </head>
- <body>
- <?php
- require_once("../../dbconnection.php");
- ?>
- <?php
- @$cat=$_GET['cat'];
- if(strlen($cat) > 0 and is_numeric($cat))
- { // to check if $cat is numeric data or not.
- echo "Data Error";
- exit;
- }
- // Getting the data from Mysql table for first list box
- $quer2=mysql_query("SELECT DISTINCT PARK FROM PARK");
- // for second drop down list we will check if category is selected else we will display all the subcategory//
- if(isset($cat) and strlen($cat) > 0){
- $test="SELECT DISTINCT Room FROM Rooms where AREA = '";
- $test = $test . $cat . "'";
- $quer=mysql_query("$test");
- }else{$quer=mysql_query("SELECT DISTINCT Room FROM Rooms"); }
- echo "<form method=post name=f1 action='dd-check.php'>";
- // Add your form processing page address to action in above line. Example action=dd-check.php
- // Starting of first drop downlist
- echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select one</option>";
- while($noticia2 = mysql_fetch_array($quer2)) {
- if($noticia2['PARK']==@$cat){echo "<option selected value='$noticia2[PARK]'>$noticia2[PARK]</option>"."<BR>";}
- else{echo "<option value='$noticia2[PARK]'>$noticia2[PARK]</option>";}
- }
- echo "</select>";
- //Starting of second drop downlist
- echo "<select name='subcat' onchange=\"reload(this.form)\"><option value=''>Select one</option>";
- while($noticia = mysql_fetch_array($quer)) {
- echo "<option value='$noticia[Room]'>$noticia[Room]</option>";
- }
- echo "</select>";
- //Starting of the third drop downlist
- echo "<select name='subcat'><option value=''>Select one</option>";
- while($noticia = mysql_fetch_array($quer)) {
- echo "<option value='$noticia[Room]'>$noticia[Room]</option>";
- }
- echo "</select>";
- //Add your other form fields as needed here
- echo "<input type=submit value=Submit>";
- echo "</form>";
- ?>
- <?php
- require("../../disconnect.php")
- ?>
- </body>
- </html>