Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

populating dropdown

Status
Not open for further replies.

arkadia93

Programmer
Oct 19, 2006
110
GB
I am trying to populate a dropdown with name titles (Mr, Mrs etc) and set the selected value to whatever value is in the database for that record. However, there are plenty of records in the database without a title. Currently in this situation the dropdown does not get populated and remains empty. Can anybody tell me what is wrong with my code (see below)?

<td>
<%
set objCmd = server.CreateObject("ADODB.Command")
objCmd.ActiveConnection = strConnection2
objCmd.CommandType = adCmdStoredProc
objCmd.CommandText = "GetContactTitles"
set rsContactTitles = objCmd.Execute

%>
<select name=ContactTitle><%
do while not rsContactTitles.eof

'if a code has been selected, set it as selected
if (Not IsNull(rsLog("Title"))) then
if (rsContactTitles("ContactTitle") = rsLog("Title"))then
Response.Write "<option value=" & rsContactTitles("ContactTitle") & " selected>"& rsContactTitles("ContactTitle")& "</option>"
else
Response.Write "<option value=" & rsContactTitles("ContactTitle") & " >"& rsContactTitles("ContactTitle") & "</option>"
end if
'if no code has been selected, set it as selected

end if
rsContactTitles.movenext
loop

set rsContactTitles = nothing
set objCmd = nothing
%>
</select>
</td>
 
I changed it to this to get it working :

<select name=ContactTitle><%
do while not rsContactTitles.eof

'if a code has been selected, set it as selected
if (Not IsNull(rsLog("Title"))) then
if (rsContactTitles("ContactTitle") = rsLog("Title"))then
Response.Write "<option value=" & rsContactTitles("ContactTitle") & " selected>"& rsContactTitles("ContactTitle")& "</option>"
else
Response.Write "<option value=" & rsContactTitles("ContactTitle") & " >"& rsContactTitles("ContactTitle") & "</option>"
end if
'if no code has been selected, set it as selected
else
Response.Write "<option value=" & rsContactTitles("ContactTitle") & " >"& rsContactTitles("ContactTitle") & "</option>"
end if
rsContactTitles.movenext
loop

set rsContactTitles = nothing
set objCmd = nothing
%>
</select>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top