Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Oct 2008
    Thanked 0 Times in 0 Posts

    How to make dynamic drop boxes


    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";
    while ($row=mysql_fetch_array($result_mealtype)) 
        $type_options.="<OPTION VALUE=\"$typeid\">".$typename;
    		Meal Type:
    		<select name="remove_type">
    		<option><?php echo $type_options?></option>

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Saskatoon, Saskatchewan
    Thanked 2,662 Times in 2,631 Posts
    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?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts