If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > Pre-select a menu item from a cookie

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-06-08, 20:11
full monty full monty is offline
Registered User
 
Join Date: Jan 2004
Posts: 22
Pre-select a menu item from a cookie

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
Reply With Quote
  #2 (permalink)  
Old 09-07-08, 07:01
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Code:
<select name="Batch" id="Batch">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option selected="selected" value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
__________________
George
Twitter | Blog
Reply With Quote
  #3 (permalink)  
Old 09-07-08, 17:16
full monty full monty is offline
Registered User
 
Join Date: Jan 2004
Posts: 22
Have I missed something? Which line(s) of code should I change?
Reply With Quote
  #4 (permalink)  
Old 09-08-08, 04:42
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
In FF the bold text stands out, but not in ruddy IE!
Code:
<option selected="selected" value="3">3</option>
__________________
George
Twitter | Blog
Reply With Quote
  #5 (permalink)  
Old 09-08-08, 12:18
full monty full monty is offline
Registered User
 
Join Date: Jan 2004
Posts: 22
I cheated/gave up on the For statement as I was getting odd results - but the following works fine:

<select name="Batch" id="Batch">
<option <%If BatchSelected = 0 Then Response.Write("selected=""selected""") End If%> value="0">0</option>
<option <%If BatchSelected = 1 Then Response.Write("selected=""selected""") End If%> value="1">1</option>
<option <%If BatchSelected = 2 Then Response.Write("selected=""selected""") End If%> value="2">2</option>
<option <%If BatchSelected = 3 Then Response.Write("selected=""selected""") End If%> value="3">3</option>
<option <%If BatchSelected = 4 Then Response.Write("selected=""selected""") End If%> value="4">4</option>
<option <%If BatchSelected = 5 Then Response.Write("selected=""selected""") End If%> value="5">5</option>
<option <%If BatchSelected = 6 Then Response.Write("selected=""selected""") End If%> value="6">6</option>

</select>
Reply With Quote
  #6 (permalink)  
Old 09-08-08, 16:28
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Code:
<select name="Batch" id="Batch">
    <%
        Dim i
        strBatchSelected = ""

        For i=0 to 5
    %>
    <option value='<%= i %>'
        <%
            If i = BatchSelected Then
                Response.Write " selected='selected' "
            End If
        %>
    >
        <%= i %>
    </option>
    <%
        Next i
    %>
</select>
__________________
George
Twitter | Blog
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On