Jump to content

Complicated Dynamic Dropdowns


fireman

Recommended Posts

Twofold issue here:

First, I need to update a drop down based on the input from another drop down in the same form.

 

I am dynamically filling dropdown 1 from db

 

<?php
$result = mysql_query("SELECT cat_name FROM cat_list WHERE cat_filter = 'E'", $db);
?>

<form name="engMaint" method="post" action="<?php echo $PHP_SELF; ?>">
  <div align="center">
  <table width="500" border="1" align="center" cellpadding="4" cellspacing="0">
    <tr>	  
      <td width="200" align="left">
        <select name="engMaintCat" id="engMaintCat">
  <?php while ($row = mysql_fetch_array($result)){ ?>
            <option selected>Select</option>          
            <option><?php echo $row[cat_name]; ?></option>
  <?php } ?>
        </select>        
      </td>
      <td width="200" align="left">
        <select name="engMaintList" id="engMaintList">
	  What Goes Here???
</select>        
      </td>
    </tr>
  </table>
  </div>
</form>

 

Now I know JavaScript will be involved utilizing "onChange".  I don't know how to implement it though.

It is tricky because I there needs to be another db call to get the fields for the second drop down.

 

EX. A few of the selections in dropdown 1 will be:

 

Ice Cream

Candy

Fruit

 

If Ice Cream is selected I will query table 'cat_icecream' and select field 'icecream_flavors' to populate dropdown 2 with:

 

Chocolate

Vanilla

Strawberry

 

or if Fruit is selected in dropdown1 than I query table 'cat_fruit' and select field 'fruit_type' to populate dropdown 2 with:

 

Apple

Grapes

Orange

 

Part two of my request is that I need a "Add" button to duplicate the form on the same page. (of course with only dropdown 1 filled.)

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.