[eluser]AlexPOWER[/eluser]
Hi,
I have one table in my database where i store my categories and subcategories...
(like)
id
name
parent
and i want to create dropdown for category and for each under category (total 5 dropdown).
Code:
<html>
<body>
[removed]
function reload(form){
var val=form.cat.options[form.cat.options.selectedIndex].value;
self.location='np.inc.php?cat=' + val;
}
[removed]
<fieldset style="border: 1px dashed blue;">
<legend>Add Product</legend>
<?php
///// Vazeca scripta
$quer2=mysql_query("SELECT name,id FROM categories WHERE parent = 0 ORDER BY name");
$cat= $_GET['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 name,id FROM categories WHERE parent = $cat ORDER BY name");
}
//check if $cat is numeric data or not.
if(strlen($cat) > 0 and !is_numeric($cat))
{
echo "Data Error";
exit;
} */
echo "<form method=post name=form1 action=''>";
echo "<table cellspacing =\"2\" cellpadding =\"3\">";
echo "<tr><td>Category</td>";
echo "<td>";
////////// Starting of first drop downlist /////////
echo "<select name='cat' id='cat'>
<option value=''>Select one...</option>";
while($noticia = mysql_fetch_array($quer2))
{
if($noticia['id']==@$cat)
{
echo "<option selected value='$noticia[id]'>$noticia[name]</option>"."<BR>";
}else
{
echo "<option value='$noticia[id]'>$noticia[name]</option>";
}
}
echo "</select>";
////////////////// This will end the first drop down list ///////////
echo "</td></tr>";
echo "<tr><td>Sub Category</td>";
echo "<td>";
////////// Starting of second drop downlist /////////
echo "<select name='subcat' id='subcat'><option value=''>Select one...</option>";
while($noticia2 = mysql_fetch_array($quer))
{
if($noticia2['name']==@$subcat){echo "<option selected value='$noticia2[id]'>$noticia2[name]</option>"."<BR>";}
echo "<option value='$noticia2[name]'>$noticia2[name]</option>";
}
echo "</select>";
echo "</td></tr>";
echo "</table>";
echo "<input type='hidden' value='".htmlspecialchars($cat)."'>";
echo "<input type=submit value=Submit>";
echo "</form>";
?>
</fieldset>
</body>
</html>
If a user select option from first dropdown,the second one will populate with options for selected option from first dropdown.
PLEASE HOW CAN I DO THAT!
Is that possibile?
PLEASE HELP!