Alex C
06-03-2004, 07:05 PM
Hi,
I'm trying to submit a form back to itself and then retain the item that was selected in a dropdown menu, The menu is created by grabbing entries from the database. This all works fine. But it's the line If KeepLocation2 = RsLocation("LocationID") Then that seems to never be true. But I've even tested it and KeepLocation2 certainly does equal one of the LocationID column's values. So each time the form is submited back to itself the value is lost and the dropdown menu is created as default again.
Note, I haven't included all the code, but this is basicly the only code that has anything to do with that option box. The db connection etc is all fine as other input boxes/text boxes etc in this form keep their value ok.
Here is my code:
KeepLocation2 = Request.Form("Location2")
<%
dim RsLocation ' Record set used to display database contents
dim SqlCommandLocation ' The SQL command to be sent to database
' Create command string
SqlCommandLocation = _
" SELECT" _
& " LocationID" _
& " , LocationDesc" _
& " FROM" _
& " Location"
' Execute command string
Set RsLocation = SQLQuery(cnDB, SqlCommandLocation)
%>
<select name="Location2" size="1">
<option value="0">
<%
Do Until RsLocation.EOF
If KeepLocation2 = RsLocation("LocationID") Then
Response.Write "<option selected value=""" & RsLocation("LocationID") & """>" & RsLocation("LocationDesc") & vbCrLf
Else
Response.Write "<option value=""" & RsLocation("LocationID") & """>" & RsLocation("LocationDesc") & vbCrLf
End If
RsLocation.MoveNext
Loop
' Close off the connections and clear the connection objects
RsLocation.Close
Set RsLocation = Nothing
%>
</select>
Thanks,
Alex
I'm trying to submit a form back to itself and then retain the item that was selected in a dropdown menu, The menu is created by grabbing entries from the database. This all works fine. But it's the line If KeepLocation2 = RsLocation("LocationID") Then that seems to never be true. But I've even tested it and KeepLocation2 certainly does equal one of the LocationID column's values. So each time the form is submited back to itself the value is lost and the dropdown menu is created as default again.
Note, I haven't included all the code, but this is basicly the only code that has anything to do with that option box. The db connection etc is all fine as other input boxes/text boxes etc in this form keep their value ok.
Here is my code:
KeepLocation2 = Request.Form("Location2")
<%
dim RsLocation ' Record set used to display database contents
dim SqlCommandLocation ' The SQL command to be sent to database
' Create command string
SqlCommandLocation = _
" SELECT" _
& " LocationID" _
& " , LocationDesc" _
& " FROM" _
& " Location"
' Execute command string
Set RsLocation = SQLQuery(cnDB, SqlCommandLocation)
%>
<select name="Location2" size="1">
<option value="0">
<%
Do Until RsLocation.EOF
If KeepLocation2 = RsLocation("LocationID") Then
Response.Write "<option selected value=""" & RsLocation("LocationID") & """>" & RsLocation("LocationDesc") & vbCrLf
Else
Response.Write "<option value=""" & RsLocation("LocationID") & """>" & RsLocation("LocationDesc") & vbCrLf
End If
RsLocation.MoveNext
Loop
' Close off the connections and clear the connection objects
RsLocation.Close
Set RsLocation = Nothing
%>
</select>
Thanks,
Alex