View Full Version : help drop down menu issue

05-08-2009, 05:30 PM
Hi all hope someone can help me figure this out...it is driving me nuts

I have some drop down menus that are populated using data from a MySql DB

the first set of drop down menus works fine...when the user select an option from the first menu only certain records are displayed in the second menu and so on to the third...you can check it at this link (http://www.napcon-communications.com/connect3/form_ITA_drop.php)

however if I add more drop down menus to the page, they won't work and even the first set of menus wont work anymore...
check out what happens here (http://www.napcon-communications.com/connect3/form_ITA_drop2.php)

I believe it has to do with the javascript controllig the menu...

Can someone help me add more drop down menu to the page? or eventually tell me a different way to achieve this?
the menu should always be in set of 3...

here is the code I am working with so far...(working code)


require "config.php";

<!doctype html public "-//w3c//dtd html 3.2//en">


<title>modulo commissioni online</title>

<SCRIPT language=JavaScript>
function reload(form)
var val=form.cat.options[form.cat.options.selectedIndex].value;
self.location='form_ITA_drop.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;

self.location='form_ITA_drop.php?cat=' + val + '&cat3=' + val2 ;


///////// Getting the data from Mysql table for first list box//////////
$quer2=mysql_query("SELECT DISTINCT category,cat_id FROM category order by category");
///////////// End of query for first list box////////////

/////// for second drop down list we will check if category is selected else we will display all the subcategory/////
$cat=$HTTP_GET_VARS['cat']; // This line is added to take care if your global variable is off
if(isset($cat) and strlen($cat) > 0){
$quer=mysql_query("SELECT DISTINCT subcategory,subcat_id FROM subcategory where cat_id=$cat order by subcategory");
}else{$quer=mysql_query("SELECT DISTINCT subcategory,subcat_id FROM subcategory order by subcategory"); }
////////// end of query for second subcategory drop down list box ///////////////////////////

/////// for Third drop down list we will check if sub category is selected else we will display all the subcategory3/////
$cat3=$HTTP_GET_VARS['cat3']; // This line is added to take care if your global variable is off
if(isset($cat3) and strlen($cat3) > 0){
$quer3=mysql_query("SELECT DISTINCT subcat2 FROM subcategory2 where subcat_id=$cat3 order by subcat2");
}else{$quer3=mysql_query("SELECT DISTINCT subcat2 FROM subcategory2 order by subcat2"); }
////////// end of query for third subcategory drop down list box ///////////////////////////

echo "<form method=post name=f1 action='confirm.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['cat_id']==@$cat){echo "<option selected value='$noticia2[cat_id]'>$noticia2[category]</option>"."<BR>";}
else{echo "<option value='$noticia2[cat_id]'>$noticia2[category]</option>";}
echo "</select>";
////////////////// This will end the first drop down list ///////////

////////// Starting of second drop downlist /////////
echo "<select name='subcat' onchange=\"reload3(this.form)\"><option value=''>Select one</option>";
while($noticia = mysql_fetch_array($quer)) {
if($noticia['subcat_id']==@$cat3){echo "<option selected value='$noticia[subcat_id]'>$noticia[subcategory]</option>"."<BR>";}
else{echo "<option value='$noticia[subcat_id]'>$noticia[subcategory]</option>";}
echo "</select>";
////////////////// This will end the second drop down list ///////////

////////// Starting of third drop downlist /////////
echo "<select name='subcat3' ><option value=''>Select one</option>";
while($noticia = mysql_fetch_array($quer3)) {
echo "<option value='$noticia[subcat2]'>$noticia[subcat2]</option>";
echo "</select>";
////////////////// This will end the third drop down list ///////////