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 5 of 5
  1. #1
    New Coder
    Join Date
    Feb 2006
    Posts
    62
    Thanks
    1
    Thanked 0 Times in 0 Posts

    ASP Generated Form Select Multiple Not Working Properly

    I'm using a Select form element with the Multiple attribute set in an ASP page to add data to a database, but the problem is that only one of the selected options is showing up in the table. The code is as follows:

    <select name="type" multiple rows="3">
    <option value="">Select</option>
    <%
    While (NOT rsStyle.EOF)
    %>
    <option value="<%=(rsStyle.Fields.Item("style").Value)%>"><%=(rsStyle.Fields.Item("style").Value)%></option>
    <%
    rsStyle.MoveNext()
    Wend
    If (rsStyle.CursorType > 0) Then
    rsStyle.MoveFirst
    Else
    rsStyle.Requery
    End If
    %>
    </select>

    Can anyone suggest why the 2nd selected option is not showing up in the database field?

  • #2
    Regular Coder
    Join Date
    Mar 2007
    Posts
    505
    Thanks
    1
    Thanked 19 Times in 19 Posts
    You always need to movefirst before you can movenext.

    Try:

    Code:
    rsStyle.movefirst
      while not rsStyle.eof
         ....
      rsStyle.movenext
    wend

    Also, why are you running this through the recordset instead of putting everything into an array? Arrays are more efficient and can be used multiple times per page. Just something for you to think about.
    To say my fate is not tied to your fate is like saying, 'Your end of the boat is sinking.' -- Hugh Downs
    Please, if you found my post helpful, pay it forward. Go and help someone else today.

  • #3
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,065
    Thanks
    4
    Thanked 8 Times in 8 Posts
    You only need to use the .MoveFirst method if you are just using pure ADO to open the table. If you are opening the table with a select statement and the .Open method of the recordset object, or you are filling the recordset with the .Execute method of the connection object then you do not need to use .MoveFirst.

    Code:
    'using ADO to open the table  not recommended for tables with many rows
    Dim sConnection
    Dim oRs
    
    sConnection = "myDSN_or_DSNLESS_Connection"
    Set oRs = Server.CreateObject("ADODB.Recordset")
    
    oRs.Open "MyTable", sConnection, 1, 2, &H0002 '&H0002 is the same as adCmdTable
    oRs.MoveFirst
    While NOT oRs.EOF
    	Response.Write "<option value=""" & oRs("style") & """>" & oRs("style") & "</option>"
    	oRs.MoveNext
    Wend
    
    
    'opening an ADO recordset object and putting the data into that using a Select statement
    Dim sConnection
    Dim oRs
    Dim sSQL
    
    sConnection = "myDSN_or_DSNLESS_Connection"
    sSQL = "SELECT style FROM MyTable"
    Set oRs = Server.CreateObject("ADODB.Recordset")
    oRs.Open sSQL, sConnection,0,1
    While NOT oRs.EOF
    	Response.Write "<option value=""" & oRs("style") & """>" & oRs("style") & "</option>"
    	oRs.MoveNext
    Wend
    
    
    
    'Using the Execute method of the connection object to fill the recordset
    Dim oConn
    Dim sConnection
    Dim oRs
    Dim sSQL
    
    Set oConn = Server.CreateObject("ADODB.Connection")
    sConnection = "myDSN_or_DSNLESS_Connection"
    oConn.Open sConnection
    sSQL = "SELECT style FROM MyTable"
    Set oRs = oConn.Execute(sSQL)
    While NOT oRs.EOF
    	Response.Write "<option value=""" & oRs("style") & """>" & oRs("style") & "</option>"
    	oRs.MoveNext
    Wend

  • #4
    New Coder
    Join Date
    Feb 2006
    Posts
    62
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Many thanks for the responses. The code I posted was generated by Dreamweaver and is standard Dreamweaver code. The question though, was why isn't more then one value being posted to the database since I'm using a Multiple attribute to the Select statement.... <select multiple></select>. The dropdown works fine in all other respects

  • #5
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    what code are you using to retrieve the values from the form, and can you confirm that the values its getting are those that you'd expect (ie: by doing a simple debug response.write(formValue) ?


  •  

    Posting Permissions

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