...

View Full Version : interdependent select boxes



mrjameer
11-13-2007, 05:03 PM
hi,

i have 2 select boxes on a page.what i want to do is when i select one option from 1st select box then related options will be displayed in 2nd select box.
i have the following code to display both select box options from 2 mysql tables.

or i have to go with javascript.any of your idea will be surely appreciated
regards
mrjameer




if($_GET['action']=="create_subsubcategory")
{

if(isset($_POST['Submit']))
{

$category_name=$_POST['category_name'];
$subcategory=$_POST['subcategory'];
$subsubcat=$_POST['subsubcat'];


$sql="INSERT INTO subsubcategories Values('','$category_name','$subcategory','$subsubcat')";
$result=mysql_query($sql,$db_connect) or die (mysql_error());
if($result)
{
echo "<center>NEW SUB SUB CATEGORY CREATED</center>";
}
else
{
echo "Sorry sub sub Category not created";
}
}
else
{


?>
<br><br><br>
<form name="fname" method="post" action="index.php?action=create_subsubcategory">
<table width="350" border="1" cellspacing="0" cellpadding="0" align="center" class="border">
<tr>
<td>
<table width="350" border="1" cellspacing="1">
<tr align="center">
<td colspan="5" class="analyzer">Create Sub Sub Category</td>
</tr>
<tr align="center">



<td class="analyzer"><select name="maincat"><option value=''>Select a Category....</option><?php

$sql="SELECT * FROM categories";
$result=mysql_query($sql) or die (mysql_error());
while($newarray=mysql_fetch_array($result))
{

$category_name=$newarray['category_name'];


echo"<option value='$category_name'>$category_name</option>";

}

echo"</select>";


?></td><td class="analyzer">MainCategory</td></tr>
<tr align="center"><td class="analyzer"><select name="maincat"><option value=''>Select a Sub Category....</option><?php

$sql="SELECT * FROM subcategories";
$result=mysql_query($sql) or die (mysql_error());
while($newarray=mysql_fetch_array($result))
{

$subcategory=$newarray['subcategory'];


echo"<option value='$subcategory'>$subcategory</option>";

}

echo"</select>";


?></td><td class="analyzer">Sub Category</td></tr>
<tr align="center"><td class="analyzer"><input type="text" name="subsubcat" value=""></td><td class="analyzer">Sub Sub Category</td></tr>
<tr>
<td class="analyzer" colspan="2" align="center"><input type="submit" name="Submit" value="Submit"></td>


</table>
</table>

<?php

}

}

Fumigator
11-13-2007, 05:12 PM
Same question just asked:

http://codingforums.com/showthread.php?t=127707



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum