Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Asp Select Box Remember

    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.

    Example.

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

    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
    </select>

    automatically!

    Thanks in advance.

    Ryan!

  • #2
    Regular Coder
    Join Date
    Sep 2002
    Location
    Adelaide, Australia
    Posts
    472
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Well, you could do it like this.

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

    then,
    Code:
    <%
    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
    </select>
    
    <%
    RS.Close
    conn.Close
    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..
    Last edited by reubenb; 09-02-2004 at 12:59 PM.

  • #3
    New to the CF scene
    Join Date
    Sep 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks bud!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •