Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need help with option selected - Select Tag

    I am using a select tag on my page and the problem I am having is that when the page is submitted I can determine which option is selected, but the page reloads with the original option selected before the change was made. I tried storing the value in a hidden field and within the for loop used to create the options, I used an if..then..clause but that didn't work. However when I "hard code" the value into the hidden field variable it works correctly.

  • #2
    New Coder
    Join Date
    Jul 2007
    Location
    North Carolina, US
    Posts
    32
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Here's an example, but there are other ways to do this that might be simpler depending on your code. If you want to post the code I'll take a look at it.
    Code:
    <select name="Dropdown" size="1" tabindex="23">
       <option selected value="One">One</option>
    <%
       Select Case Request.Form("Dropdown")
          Case "Two"
    %>
       <option selected value="Two">Two</option>
       <option value="Three">Three</option>
       <option value="Four">Four</option>
    <%
          Case "Three"
    %>
       <option value="Two">Two</option>
       <option selected value="Three">Three</option>
       <option value="Four">Four</option>
    <%
          Case "Four"
    %>
       <option value="Two">Two</option>
       <option value="Three">Three</option>
       <option selected value="Four">Four</option>
    <%
          Case Else
    %>
       <option value="Two">Two</option>
       <option value="Three">Three</option>
       <option value="Four">Four</option>
    <%
       End Select
    %>
    </select>

  • #3
    New Coder
    Join Date
    Jul 2007
    Location
    North Carolina, US
    Posts
    32
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Here's an example, but there are other ways to do this that might be simpler depending on your code. If you want to post the code I'll take a look at it.
    Code:
    <select name="Dropdown" size="1" tabindex="23">
       <option selected value="One">One</option>
    <%
       Select Case Request.Form("Dropdown")
          Case "Two"
    %>
       <option selected value="Two">Two</option>
       <option value="Three">Three</option>
       <option value="Four">Four</option>
    <%
          Case "Three"
    %>
       <option value="Two">Two</option>
       <option selected value="Three">Three</option>
       <option value="Four">Four</option>
    <%
          Case "Four"
    %>
       <option value="Two">Two</option>
       <option value="Three">Three</option>
       <option selected value="Four">Four</option>
    <%
          Case Else
    %>
       <option value="Two">Two</option>
       <option value="Three">Three</option>
       <option value="Four">Four</option>
    <%
       End Select
    %>
    </select>

  • #4
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Attached is the code of what I am trying to do.

    Code:
    <html> 
    <head><title>Test</title></head> 
    <% 
    If Request.ServerVariables("HTTP_METHOD") = "POST" THEN 
        extendedStay = Request.Form("extendedStay")
        wsExtendedStay = extendedStay 
        
        'For testing purposes only.
        response.write "wsExtendedStay is = "&wsExtendedStay&""
    End If 
    %> 
    <body> 
     <form name='htlStay' method='post' action='extStay.asp'> 
    	<%     		
      response.write "<select name='extendedStay' size='1'>" 
      For i=1 to 60              
      If i=wsExtendedStay Then 
         response.write "<option value="&i&" selected>"&i&"</option>"
      Else
          response.write "<option value="&i&">"&i&"</option>" 
      End If 
      next 
      response.write "</select><br /><br />"
      response.write "<button type='submit' name='submitForm'>Submit</button>"
      %>
     </form> 
    </body> 
    </html>

  • #5
    New Coder
    Join Date
    Jul 2007
    Location
    North Carolina, US
    Posts
    32
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Change this line:
    Code:
    If i=wsExtendedStay Then
    To this:
    Code:
    If i = Int(wsExtendedStay) Then

  • #6
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks so much it worked.

  • #7
    New Coder
    Join Date
    Jul 2007
    Location
    North Carolina, US
    Posts
    32
    Thanks
    1
    Thanked 0 Times in 0 Posts
    No problem!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •