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

How do I set the default value for a combo box?

Status
Not open for further replies.

gillianm1

Programmer
Sep 8, 2000
26
IE
Hi,
I'm populating a combo box from a SQL Server table using the following code:

<SELECT id=select1 name=cboSector2>
<%Do Until rs.EOF%>
<OPTION><%=rs(&quot;Sectorname&quot;)%></Option>
<% rs.MoveNext
Loop%>
</SELECT>

My problem is that I want the combo box to show one particular record by default. Anyone know how I can do this?
Thanks in advance. [sig][/sig]
 
I am not sure of this but, I think that you might try testing for the record value you want selected
so inside of the loop you would have a test condition of some sort like

<%Do until rs.eof
if rs(&quot;Sectorname&quot;)=&quot;test&quot; then%>
<option Selected><%=rs(&quot;Sectorname&quot;)%></option>
<%else%>
<option><%=rs(&quot;Sectorname&quot;)%></option>
<%end if%>

however as I said I am not sure if selected is the right attribute name. There may be a much better way to handle this but it is what I thought of.

Hope this helps.
[sig]<p>Crystal<br><a href=mailto:crystals@genesis.sk.ca>crystals@genesis.sk.ca</a><br><a href= > </a><br>--------------------------------------------------<br>
Experience is one thing you can't get for nothing.<br>
-Oscar Wilde<br>
[/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top