I am filling a dropdown list and an HTML page with the contents of a MySQL database (the tablename is in the variable $tablename2). The file contains a single field, "BusinessCat", with 20 or so unique records. The code below is an attempt to display every category on an HTML document with a dropdown list at the top which would allow a user to select a category and jump to that category on the HTML page below. How do I capture what the user selected from the list before the HTML page is built? I think I am very close...

$catlist = mysql_query("SELECT * FROM " . $tablename2 . " order by BusinessCat");

	 echo "<select name=Category value=''>Choose a Category</option>";
 	 while($nt = mysql_fetch_array($catlist)){ 
            echo "<option value=$nt[BusinessCat]>$nt[BusinessCat]</option>";
	 echo "</select>";
$catlist = mysql_query("SELECT * FROM " . $tablename2 . " order by BusinessCat");
while($catrow = mysql_fetch_array($catlist)) {		
  // create A TARGET 						
  echo "<a name='$catrow[BusinessCat]'></a>";
  echo "<div id='CatHead'>" . $catrow['BusinessCat'] . " </div><br />" ;
  echo '<form action="#top" method="get"><input type="submit" value="Back to Top" /></form>';

Edited by Bounty Hunter: unnecessary code left in example

6 Years
Discussion Span
Last Post by diafol

Jumping via select is not suggested - it can be problematic wrt accessibility. If you do go via this, you'll need to use javascript - the onselect attribute.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.