View Full Version : Asp Select Box Remember

09-02-2004, 11:00 AM
I have a select box that I need to be remembered in a database so i can later retrieve it and edit it if need be. Can anyone help me with this.


<select name="selectbox">
<option value="apple">apple
<option value="orange">orange
<option value="pear">pear

Now if i select one of these and later down the line I want to be able to edit this option how can I save what was selected, transfer that info to a database and be able to retrieve that info from a database.

Example: i selected pear on page 1
page 2 i want:

<select name="selectbox">
<option value="apple">apple
<option value="orange">orange
<option value="pear" selected>pear


Thanks in advance.


09-02-2004, 12:57 PM
:thumbsup: Well, you could do it like this.

Make a field in your table in your database called 'selected'


dsn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\yourdb.mdb;Jet OLEDB:Database Password=password;"

Set conn=Server.CreateObject("ADODB.Connection")
conn.Open dsn

SQL="SELECT * FROM table where whoevertheyare ='" & Session("UserSession") & "'"
Set RS = Server.CreateObject("ADODB.Recordset")
rs.open sql, conn

While Not RS.EOF %>

<select name="selectbox">
<option <%if RS("selected")="apple" then response.write "selected"%> value="apple">apple
<option <%if RS("selected")="orange" then response.write "selected"%> value="orange">orange
<option <%if RS("selected")="pear" then response.write "selected"%> value="pear">pear

Set RS = Nothing
Set conn = Nothing%>

You can do the same if you want to SAVE it into a database.. after each page, it POSTs the info to a database, and it writes the 'selected' field.
let me know if you want to do this.

I did it really quickly, so if it doesn't make sense - let me know..
I am not quite sure if that's what you are asking..

10-12-2004, 06:45 AM
thanks bud!