By Brian B.
As a newbie to ASP I often look to 4guysfromrolla.com for answers. This time was no different however I could not find a good example that would work in my situation. After a viewing a few articles and putting my head to good use I came up with the following solution. I hope it helps to keep your sites easier to maintain.
authors note: I added the last one, just for my boss 8-)VBScript:
Connect to database.... (see other articles on this site if you need help: I recommend you start with the Database F.A.Q.)
Open a Recordset and get the information to use in the drop-down list
Ok now the recordset
oRs is full of the data needed to populate our
dynamic dropdown listbox
The next line will look through the recordset until it reaches the
EOF (end of file) or the last record in the returned results.
The next few lines are pretty easy to follow except maybe the first.
And I only added this after my boss told me he wanted NORMAL to
be the default for this particular drop-down list. The first line says if the
priority_id field equals
2 then return this option as the default
item in the drop-down menu. You will need set this to match your own
criteria. 2 = Normal in my table. If you set it to 1 then it will show
as the default menu item. Change it and see for yourself in the example
All of the above ASP code would go at the top of the file within the ASP tags <% %>. And below is the HTML code to make it show the menu items.
<html><head><title>Dynamic Drop-Down Menu Example</title></head>
<form method="POST" action="dropdown_ex.asp">
<p><select size="1" name="dropdown_menu">
A working .asp file, the Access database is included
in the download file below.
|Return to user tips...|