Log in

View Full Version : populating one drop down with another



nasirmunir
03-25-2009, 04:10 PM
I want to populate one drop down with another.
The two drop downs are Projects, and Tasks. If a user select a project, the tasks should populate according to the project selected.
I can populate task list on the basis of project id, but I don't know how to refresh that list every time a different project is selected. Any help? direction?

my project drop down:


<select name="pid">
[INDENT][INDENT][INDENT]<?
while ($row=mysql_fetch_array($resultProject)) {

$pid=$row["pid"];
$value=$row["project_name"];
?>

<option value="<?=$pid?>" ><?=$value?></option>
<? }
?>
</select>

and my tasks drop down:


<select name="tid">
<?
$sqlTask="SELECT * from tasks where pid=$pid ;";
$resultTask=mysql_query($sqlTask);
$optionsTask="";

while ($row=mysql_fetch_array($resultTask)) {

$pid=$row["tid"];
$value=$row["task_name"];

?>
<option value="<?=$tid?>"><?=$value?></option>
<? }
?>
</select>

Falkon303
03-27-2009, 05:47 PM
Check out these guys -

http://www.dynamicdrive.com/dynamicindex1/chainedmenu/index.htm

They have some awesome stuff, including the dynamic dropdown menu.

it seems you haven't fully gotten into bed with php. you are also going to have to use javascript to post an 'onchange' action, so you might as well go dynamic.



<?
$selection = "hotdogs";
?>

<select id="<? echo $selection; ?>condiments" >
<?
////below is mysql qeury stuff of course//
connect();
$pullmt = mysql_query("SELECT * FROM blah WHERE identity = '".mysql_real_escape_string($selection)."'") or die()
while($resrow = mysql_fetch_assoc($pullmt))
{
echo "<option value=\"".$resrow['identity']."\">".$resrow['identity']."</option>";
}
mysql_close();
?>
</select>