...

View Full Version : ASP Generated Form Select Multiple Not Working Properly



SteveSensei
10-05-2007, 05:21 PM
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?

Daemonspyre
10-05-2007, 05:58 PM
You always need to movefirst before you can movenext.

Try:


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.

miranda
10-05-2007, 09:09 PM
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.



'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

SteveSensei
10-06-2007, 03:49 AM
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

Spudhead
10-08-2007, 01:16 PM
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) ?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum