View Full Version : drop down does not select the choice

09-02-2005, 12:26 AM
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?


09-02-2005, 01:13 AM
What you need to do is something like this:

do until rs.eof = true
if rs.fields("id") = selected_id then
<option value="<%=rs.fields("id") %>" selected="selected"><%=rs.fields("name")%></option>
<option value="<%=rs.fields("id") %>"><%=rs.fields("name")%></option>
end if

That should get you going. Please forgive any syntax errors, my ASP is a little rusty.

09-02-2005, 09:11 AM
you could also write it as:

<% while not rs.eof %>
<option value = "<%=rs("id")%>" <% if cint(rs("id") = cint(id) then response.write "selected" %>><%=rs("name")%></option>

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.