I have used a cookie to store the value of a previously submitted select menu.
The script reads the cookie and attempts to pre-select the menu item based upon the cookie value.
Except it doesn't work for me and I cannot work out why.
<%
If Request.Cookies ("SamplesInBatch")("Batch") <> "" Then
BatchSelected = Request.Cookies ("SamplesInBatch")("Batch")
Else
BatchSelected = 0
End If
%>
<select name="Batch" id="Batch">
<% Dim i
strBatchSelected = ""
For i=0 to 5
IF i = BatchSelected Then
'Response.Write(BatchSelected)
strBatchSelected = "selected"
End If
response.Write("<option " & strBatchSelected & " value=""" & i & """>" & i & "</option>" & "")
Next
%>
</select>
If the value of the cookie ("SamplesInBatch")("Batch") is 3, then I would like to get the following:
<select name="Batch" id="Batch">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option selected value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
Any ideas where I am going wrong? What's strange is that if I change the line:
'IF i = BatchSelected Then' to
'IF i = 3 Then' - I get some very strange results and menu item 3 and above gets the 'selected' treatment to give:
<select name="Batch" id="Batch">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option selected value="3">3</option>
<option selected value="4">4</option>
<option selected value="5">5</option>
</select>
Cheers,
Alski