...

View Full Version : drop down does not select the choice



otherjugdish
09-01-2005, 11:26 PM
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.

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


<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.

NancyJ
09-02-2005, 08: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>
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum