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

Populate Dropdown Via Loop..Need Middle choice selected.

Status
Not open for further replies.
Mar 25, 2004
146
US
Hi,
I'm populating an option box with 5 fields via a loop from a database. I need field 3 to be the selected field. How do I do this since I'm using a loop.

-Ryan
 
You haven't said what server-side language you're using, so I'll assume it's server-side ASP written in Javascript.

You'd use something like:

Code:
<%
var recordCount = 0;
var selectedStr = '';
%>
<select...>
<%
while (!rs.EOF)
{
   recordCount++;
   selectedStr = (recordCount == 3) ? 'selected' : '';
%>
   <option value="<%=rs('code').value%>"<%selectedStr%>><%=rs('name').value%></option>
<%
   rs.MoveNext();
}
%>
</select>

Hope this helps,
Dan


 

What is PSP?

I'm sure you can adapt the example I've given for your own use, anwyay...

Hope this helps,
Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top