/    Sign up×
Community /Pin to ProfileBookmark

interdependent select boxes

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

[code=php]
<?php
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

}

}
?>
[/code]

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@knowjNov 13.2007 — you will need to use an AJAX (if the 2nd selection is dynamic) or Javascript solution.

Another option is having the user submit and the loading the 2nd results.
×

Success!

Help @roshanjameer spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...