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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    drop down does not select the choice

    I have a form that opens based on the values in a record and there are drop downs in the form. However, when the form opens, the drop down is not selecting the value in the field.

    For example, there is a value of 4 in the field and the dropdown contains a 4, matched to "John Smith". I would like the name to appear in the combo box, but all it does is select the first one in the list.

    Does this sort of thing require java or can it be handled in the asp code?

    Thanks.

  • #2
    Regular Coder
    Join Date
    Jun 2003
    Location
    Silicon Forest
    Posts
    155
    Thanks
    0
    Thanked 5 Times in 5 Posts
    What you need to do is something like this:
    psuedocode
    Code:
    <select>
    <%
    do until rs.eof = true
       if rs.fields("id") = selected_id then
                %>
                <option value="<%=rs.fields("id") %>" selected="selected"><%=rs.fields("name")%></option> 
                 <%
        else
                %>
                <option value="<%=rs.fields("id") %>"><%=rs.fields("name")%></option> 
                 <%
       end if
       rs.movenext
    loop
    %>
    </select>
    That should get you going. Please forgive any syntax errors, my ASP is a little rusty.
    Last edited by CrzySdrs; 09-02-2005 at 12:17 AM.
    Whats the point of a signature?

  • #3
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    you could also write it as:
    Code:
    <% while not rs.eof %>
    <option value = "<%=rs("id")%>" <% if cint(rs("id") = cint(id) then response.write "selected" %>><%=rs("name")%></option>
    rs.movenext
    wend 
    %>
    obviously replace the relavent parts with whatever recorsets and variables you use in your code.
    Notice that I converted both to integers before comparing - since "4" does not = 4, not knowing anything about your data or code this will ensure they are the same type.


  •  

    Posting Permissions

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