Jump to content

Three dropdown


mmarif4u

Recommended Posts

hi

I know that is not so difficult but......

I have a page where there are three dropdown ,I want to populate these by depending on eachother

like 2nd one depend on 1st and 3rd one depend on 2nd.

 

I have the following code , i am trying to solve it but no luck.

 

Code:

<html>

<head>
<title>Multiple drop down list box from plus2net</title>
<meta name="GENERATOR" content="Arachnophilia 4.0">
<meta name="FORMATTER" content="Arachnophilia 4.0">
<SCRIPT language=JavaScript>
function reload(form)
{
var val=form.cat.options[form.cat.options.selectedIndex].value;
self.location='dd.php?cat=' + val ;
}
</script>
<SCRIPT language=JavaScript>
function reload(sub)
{
var val=sub.subcat.options[sub.subcat.options.selectedIndex].value;
self.location='dd.php?subcat=' + val ;
}
</script>
</head>

<body>
<?
@$cat=$_GET['cat']; // Use this line or below line if register_global is off
@$subcat=$_GET['subcat'];
///////// Getting the data from Mysql table for first list box//////////
$quer=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/////
if(isset($cat) and strlen($cat) > 0){
$quer2=mysql_query("SELECT DISTINCT subcategory FROM subcategory where cat_id=$cat order by subcategory");
}else{$quer2=mysql_query("SELECT DISTINCT subcategory FROM subcategory order by subcategory"); }

// third dropdown
if(isset($subcat) and strlen($subcat) > 0){
$quer3=mysql_query("SELECT DISTINCT name FROM sub_cat where id=$subcat order by name");
}else{$quer3=mysql_query("SELECT DISTINCT name FROM sub_cat order by name"); }

echo "<form method=post name=f1 action='dd.php'>";

echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select one</option>";
while($noticia = mysql_fetch_array($quer)) {
if($noticia['cat_id']==@$cat){echo "<option selected value='$noticia[cat_id]'>$noticia[category]</option>"."<BR>";}
else{echo  "<option value='$noticia[cat_id]'>$noticia[category]</option>";}
}
echo "</select>";

echo "<select name='subcat' onchange=\"reload(this.sub)\"><option value=''>Select one</option>";
while($noticia2 = mysql_fetch_array($quer2)) {
//if($noticia['id']==@$subcat){echo "<option selected value='$noticia2[id]'>$noticia2[subcategory]</option>"."<BR>";}
//else{
echo  "<option value='$noticia2[subcategory]'>$noticia2[subcategory]</option>";}

echo "</select>";

echo "<select name='sub'><option value=''>Select one</option>";
while($noticia3 = mysql_fetch_array($quer3)) {
echo  "<option value='$noticia3[id]'>$noticia3[name]</option>";
}
echo "</select>";

echo "<input type=submit value=Submit>";
echo "</form>";
?>
</body>
</html>

 

any help will be aprriciated.

thanks.

Link to comment
https://forums.phpfreaks.com/topic/50196-three-dropdown/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.