Quick Jump Menu Without a Go Button

This is a nice and clean quick tip to create a jump menu without a "go" button. Say for example you have a list of items in a database that need to have a details page based upon their "id". This will create a dropdown menu that is auto populated with the most up to date list.
  1.  
  2. <?
  3.  
  4. // Connect to your MySQL database
  5. require "path/to/your/database/connection/";
  6.  
  7. // Select the data
  8. $select = mysql_query( "SELECT * FROM your_table_name ORDER BY column_name ASC") ord die("SELECT Error: ".mysql_error());
  9.  
  10. ?>
  1. // This is a bit of javascript to grab the value of the <option> selected
  2. <select onchange="window.open(this.options[this.selectedIndex].value,'_top')">
  1. <?
  2.  
  3. // Begin grabbing the rows from your database
  4. while ($row = mysql_fetch_array($select)) {
  5.  
  6. ?>
  7.  
  8. <option value="details.php?id=<? echo $row['id']; ?>">
  9. <? echo $row['column_name']; ?>
  10. </option>
  11.  
  12. <?
  13.  
  14. }
  15.  
  16. ?>
  17.  
  18. </select>
Post a comment
  1. Jeremiah Wall

    Thanks a ton for this. Really insightful.






^