hi guys! can you look for my script im required to use php. i have two comboboxes namely cat and sub cat. and i have a textbox. my logic goes to when i select item from cat it will display its sub items in subcat. and then when i select subcat it will display the information about the sub items in textbox.. my problem is when i select cat it display the information about the subitem that is supposed to be after selecting the subcat. can anyone help me out of this? thanks
<SCRIPT language=JavaScript>
function reload(form){
var val=form.cat.options[form.cat.options.selectedIndex].value;
self.location='ordering.php?cat=' + val ;
}
function populate(form){
document.f1.quan.value=document=f1.subcat.value;
}
</script>
<?
mysql_connect("localhost","root","");
mysql_select_db("databasename") or die(mysql_error());
$quer2=mysql_query("SELECT DISTINCT item,id FROM product order by item");
if(isset($cat) and strlen($cat) > 0){
$quer=mysql_query("SELECT DISTINCT subitem,itemcolor FROM itemlist where id=$cat order by subitem");
}
else
{
$quer=mysql_query("SELECT DISTINCT subitem,itemcolor FROM itemlist order by subitem");
}
echo "<table border=1>";
echo "<form method=post name=f1 action=''>";
////////// Starting of first drop downlist /////////
echo "<select name='cat' onchange=\"reload(this.form)\"><option value='0' selected>Select one</option>";
while($row = mysql_fetch_array($quer2)) {
if($row['id']==@$cat)
{
echo "<option selected value='$row[id]'>$row[item]</option>"."<BR>";
}
else
{
echo "<option value='$row[id]'>$row[item]</option>";}
}
echo "</select>";
////////////////// This will end the first drop down list ///////////
////////// Starting of second drop downlist /////////
echo "<select name='subcat'><option value=''>Select one</option>";
$row2 = mysql_fetch_array($quer);
echo "<option value='$row2[id]'>$row2[subitem]</option>";
echo "<tr><th>Product Code:<th><input type='text' value='$row2[itemcolor]'> <tr>";
echo "</select>";
////////////////// This will end the second drop down list ///////////
echo "<input type=submit value=Submit>";
echo "</form>";
?>