...

View Full Version : How to make dynamic drop boxes



metomeya
02-22-2010, 01:16 AM
Hi,

This is sort of a follow up to my last post

I was wondering the best/easiest way to make dynamic drop boxes. Do I need to use Javascript?

Here is some of the code I'm working with. I want select a meal type (breakfast, lunch, dinner, etc.) and then have the subsequent drop box pull up only the relevant meals



$sql_mealtype="SELECT typeID, typeName FROM mealtypes ORDER BY typeID";
$result_mealtype=mysql_query($sql_mealtype);

$mealtype_options="";
while ($row=mysql_fetch_array($result_mealtype))
{
$typeid=$row["typeID"];
$typename=$row["typeName"];
$type_options.="<OPTION VALUE=\"$typeid\">".$typename;
}




<form>
Meal Type:
<br>
<select name="remove_type">
<option><?php echo $type_options?></option>

</form>

<form>
Recipe:
<br>
<select>
<option>#####</option>
</select>
</form>

Fou-Lu
02-22-2010, 02:53 PM
The only way to do this directly with php, would be to ask for what 'meal' first, then submit the form, handle you're data and write a new select with just the items relating to it.
This is actually how I'd do it anyway, then link AJAX to it to handle it behind the scenes and rewrite the new data. Even though forms that go through box after box just to get the specific related data is horrid looking, at least it will still function without the javascript involved.

So, with the code you have above here, you would use the $typeid provided by you're selection menu to determine what meal type was selected, and query you're 'meals' (maybe?) table where the mealtype is $typeid to populate the next dropdown. That make sense?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum