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

selecting the default (selected) value from a drop down list.

Status
Not open for further replies.

gus121

Technical User
Joined
May 9, 2002
Messages
298
Location
GB
Does any one have any ASP code which can dynamicly select a default (selected) value from a drop down list.

e.g: so the value from the database can be used to select the default (selected) value in a dropdown list from a choice the user made previously in anouther ASP page.

Thanks in advance

Gus
 
Code:
<SELECT NAME=frmSelect>
<OPTION VALUE=&quot;&quot;>Choose an option</OPTION>
<%
While NOT objRecordset.EOF
  If (enter your conditional criteria here) Then
    strSelected = &quot; SELECTED&quot;
  Else
    strSelected = &quot;&quot;
  End If

  Response.Write &quot;<OPTION VALUE='&quot; & objRecordset(&quot;Fieldname&quot;) & &quot;'&quot; & strSelected & &quot;>&quot; & objRecordset(&quot;Fieldname&quot;) & &quot;</OPTION>&quot;
  objRecordset.MoveNext
Wend
%>
</SELECT>
Tony
reddot.gif WIDTH=400 HEIGHT=2 VSPACE=3

 
Another way is to do this... something which I've done just yesterday... This piece of code makes the default selection of a dropdown box to be a value previously saved into the database. Hope it helps...

Assuming you have already extract the value from the database...

Variables:
txtColor - name of the dropdown box
strColor - the value of the variable extracted from the database

<Select name=&quot;txtColor&quot;>
<Option
<%If strColor=&quot;Blue&quot; Then Response.Write(&quot;selected&quot;)%> value=&quot;Blue&quot;>Blue</option>
<Option
<%If strColor=&quot;Maroon&quot; Then Response.Write(&quot;selected&quot;)%> value=&quot;Maroon&quot;>Yellow</option>
<Option
<%If strColor=&quot;Green&quot; Then Response.Write(&quot;selected&quot;)%> value=&quot;Green&quot;>Green</option>
</Select>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top