The problem isn't just your ASP, but the outputted HTML. Don't worry though...you're far from the only person to have this difficulty. I'd say half the select boxes I see, when recalled, are guilty of the same sin as it were.
But...it's an easy enough fix.
First off, when your ASP code retrieves values from the form, it looks at the value attribute of the option tag first.
In every single iteration of your loops that create your listboxes, your value is "bulletin_dropdown_menu.asp". This will be what your ASP code will retrieve when you pass it back.
What you want is something like this:
Code:
for i = 1 to R.Recordcount ' If possible, use for loops because they have an obvious finite ending. RecordCount should be a self-explanatory recordset attribute.
Response.Write "<option value=""" & R ("Month") & """" ' you don't need the .Fields or the .value. They're just code and time wasters. Simplify, man.
if R ("Month") = Request.Form ("dropdownlist") then ' It's this line that compares your old value to your new value.
Response.Write " selected=""selected"""
end if
Response.Write ">" & R ("Month") & "</option>" & VbCrLf ' the only point of the vbCrLf is to ensure that your outputted HTML code shows one option value per line. It just makes things neater.
Next
Alternatively, <option>R ("Month")</option> would work, as long as you didn't assign a value
other than R ("MONTH") to your option value.
A few tips for you as an ASP newbie:
1) Response.WRite is your friend. Use it to spit things out at every opportunity.
2) View Source is also your friend. Always view your source to see what happened vs. what you would expect.
3) Response.End can also be used to stop an ASP page dead in its tracks, rather than let it go through all the way. This can be useful if you only want to debug a section of code.
4)
Any time you open an object,
be sure to close the option and set it to nothing, in order to free up the memory used by that object. If you don't, your server will hang on to it for as long as it wants, and you don't have any control.
5) Write all objects to variables when possible. It'll make debugging and object manipulation so much easier.
e.g. Name = Request.Form ("Name")
Expiry_Date = RS ("Expiry_Date")
As you go on, you'll discover that ASP, if used correctly, can really speed up development time. Use custom subs and functions (as you have done) at every opportunity, and try to write ones that will be reusable.