Click to See Complete Forum and Search --> : Using Cookie to set form Select


PineRest
06-19-2006, 09:06 AM
Hello. I have a cookie that sets a value called "type". I have a database that stores the values in a form's Select field. I'd like the form to write 'selected' when the value in the cookie matches the value in the database.

(Example: The select values in the database are car, boat, airplane. The cookie stored is boat. So the form's select options should have 'selected' in the boat option.)

Here's the code I have (FYI, the cookie is storing the correct value):

<select name="EVE_TYPE" class="form" onBlur="XMwriteCookie('Type',MM_findObj('EVE_TYPE').value,1)" id="EVE_TYPE">
<%
While (NOT rsType.EOF)
%>
<option value="<%=(rsType.Fields.Item("TYPE_ID").Value)%>" <%If (rsType.Fields.Item("TYPE_ID").Value)= Request.Cookies("Type") Then Response.Write " selected"%>><%=(rsType.Fields.Item("TYPE_NAME").Value)%></option>
<%
rsType.MoveNext()
Wend
If (rsType.CursorType > 0) Then
rsType.MoveFirst
Else
rsType.Requery
End If
%>
</select>

russell
06-19-2006, 04:26 PM
first do a Response.Write Request.Cookies("Type")

to see that the cookie value is indeed correct.

Then change the comparison to eliminate case sensitivity issues

If Lcase((rsType.Fields.Item("TYPE_ID").Value)) = Lcase(Request.Cookies("Type")) Then

russell
06-19-2006, 04:29 PM
also, looks like you are setting the cookie in JS onblur...? why? are you using the cookie elsewhere in the script?

why not just check the form value

If Lcase(rsType.Fields.Item("TYPE_ID").Value) = Lcase(Request.Form("EVE_TYPE")) Then
Response.Write " selected"
End If

PineRest
06-20-2006, 09:57 AM
first do a Response.Write Request.Cookies("Type")

to see that the cookie value is indeed correct.

Then change the comparison to eliminate case sensitivity issues

If Lcase((rsType.Fields.Item("TYPE_ID").Value)) = Lcase(Request.Cookies("Type")) Then


That did it!!! Thanks much, Russell.

Although WHY it worked is a bit of a mystery. I doubled checked the cookie value and the option value and they were exactly the same case. :confused:

But hey! At least it's working, and that's a good piece of code to know.

Thanks again, Russell.