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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question: Dropdown box selected value

Status
Not open for further replies.

Creeder

Programmer
Jul 5, 2000
110
MY
Hi All,

Let's say the current value stored in a recordset for a field value is "D".

THen I have a dropdown box that has the following values
<%
Response.Write &quot;<SELECT NAME=cmbTest>&quot;
Response.Write &quot;<OPTION> A </OPTION>&quot;
Response.Write &quot;<OPTION> B </OPTION>&quot;
Response.Write &quot;<OPTION> C </OPTION>&quot;
Response.Write &quot;<OPTION> D </OPTION>&quot;
Response.Write &quot;<OPTION> E </OPTION>&quot;
Response.Write &quot;</SELECT>&quot;
%>

Let's say when i load up the form I want to show &quot;D&quot; as the default selected value. However using the SELECTED tag seem to create another entry in the dropdown box.

Any ideas?


 
Try this:
<SELECT NAME=cmbTest>
<%
do while not rs.eof
if rs(&quot;field_name&quot;)= &quot;D&quot; then
%>
<OPTION SELECTED>D</OPTION>
<%
else
%>
<OPTION><%= rs(&quot;field_name&quot;)%></OPTION>
<%
end if
rs.movenext
loop
%>
</SELECT>
 
What he said... or w/o the looping.
<%
Response.Write &quot;<SELECT NAME=cmbTest>&quot;
Response.Write &quot;<OPTION VALUE = 'A'> A </OPTION>&quot;
Response.Write &quot;<OPTION VALUE = 'B'> B </OPTION>&quot;
Response.Write &quot;<OPTION VALUE = 'C'> C </OPTION>&quot;
Response.Write &quot;<OPTION SELECTED VALUE = 'D'> D /OPTION>&quot;
Response.Write &quot;<OPTION VALUE = 'E'> E </OPTION>&quot;
Response.Write &quot;</SELECT>&quot;
%>
It may not be neccessary but this way it returns the same value it displays.

-Pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top