Connecting Tech Pros Worldwide Forums | Help | Site Map

Creating a dynamic drop down menu

Newbie
 
Join Date: Jun 2007
Posts: 4
#1: Aug 25 '07
I have 2 dynamic PHP dropdowns:

The second dropdown populates from the first, depending on what is selected in the first.
The page is showing issues in a department:

The first dropdown consists of departments- It has 3 options All issues, dept A, dept B
If dept A is chosen in the first dropdown, the second dropdown shows all members in dept A and all issues are shown for dept A are shown below.

Now if i choose a member in second dropdown, i want issues owned by this member to show up.

code:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. //db connection file goes here
  4.  
  5.  
  6.  
  7. if (isset($_GET["first"]))
  8. {
  9.     $first =$_GET["first"];
  10.  
  11.  
  12. }
  13. if (isset($_GET["second"]))
  14. {
  15.     $second =$_GET["second"];
  16.  
  17. }
  18.  
  19. ?>
  20. <HTML>
  21.  
  22. <script language="JavaScript">
  23.  
  24. function mySubmit()
  25. {
  26.     var formObject = document.forms['myform'];
  27.     formObject.submit();
  28. }
  29.  
  30.  
  31. <?php
  32.  
  33. </HEAD>
  34. <BODY>
  35.  
  36. <form name="myform" method="get">
  37.  
  38.         <p>Please select a dept 
  39.     <select name="first"  onChange ="mySubmit();">
  40. <option value="NULL"></option>
  41. <?php
  42.     //get members from db depending on what dept is selected
  43.  
  44.  echo '</SELECT>';
  45.  
  46. if($first != null) 
  47.     { 
  48.  
  49.     ?> 
  50.     Please select a member:&nbsp;
  51.     <select name="second" onChange="mySubmit();">        
  52.  
  53.  //get option values from db
  54.  echo '</SELECT>';
  55.  
  56. }
  57.  
  58. //if dept selected show issues for that dept
  59. //if member selected show issues only for that member
  60.  
  61.  
  62. </TABLE>
  63. </BODY>
  64. </HTML>
  65.  
Any help is appreciated.

Thank you.

pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#2: Aug 26 '07

re: Creating a dynamic drop down menu


Heya, PHP Newbie.

There are over a dozen threads on this site that cover exactly what you are looking for.

Head over to the search page and search the PHP forum for 'dynamic drop down'.
Reply