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!

setting value of dropdown to recordset field 1

Status
Not open for further replies.

arkadia93

Programmer
Oct 19, 2006
110
GB
What is the correct syntax for setting the value of a dropdown to the value of a recordset field? This is my code :

<SELECT NAME = "ContactJobRole">
<%=Response.Write rsLog("contactJobRole")%>
<OPTION VALUE="">-Select Job Role-</OPTION>
<OPTION VALUE="CP">CP</OPTION>
<OPTION VALUE="CT">CT</OPTION>
<OPTION VALUE="DV">DV</OPTION>
<OPTION VALUE="FC">FC</OPTION>
<OPTION VALUE="FD">FD</OPTION>
<OPTION VALUE="FL">FL</OPTION>
<OPTION VALUE="HR">HR</OPTION>
<OPTION VALUE="HS">HS</OPTION>
<OPTION VALUE="IT">IT</OPTION>
<OPTION VALUE="MD">MD</OPTION>
<OPTION VALUE="MK">MK</OPTION>
<OPTION VALUE="NA">NA</OPTION>
<OPTION VALUE="OF">OF</OPTION>
<OPTION VALUE="OP">OP</OPTION>
<OPTION VALUE="OS">OS</OPTION>
<OPTION VALUE="PA">PA</OPTION>
<OPTION VALUE="PT">PT</OPTION>
<OPTION VALUE="PU">PU</OPTION>
<OPTION VALUE="QA">QA</OPTION>
<OPTION VALUE="SA">SA</OPTION>
<OPTION VALUE="TC">TC</OPTION>
</SELECT>
 
There is the easy way and the less easy way to do it.

If you don't mind having a duplicate item in your dropdown list, then you can generate an initial option based on the selected value like so:
Code:
<SELECT NAME = "ContactJobRole">
     <option value="<%=rsLog("contactJobRole")%>"><%=rsLog("contactJobRole")%></option>
            <OPTION VALUE="">-Select Job Role-</OPTION>
            <OPTION VALUE="CP">CP</OPTION>
            <OPTION VALUE="CT">CT</OPTION>

Or if you don't want a duplicate and just want the existing option selected, then you could do something like this:
Code:
'assuming all of the options are available in an array called arrOptions

Response.Write "<SELECT NAME = ""ContactJobRole""><OPTION VALUE="""">-Select Job Role-</OPTION>"
Dim i
For i = 0 to UBound(arrOptions)
   Response.Write "<option value=""" & arrOptions(i) & """"
   If arrOptions(i) = rsLog("contactJobRole") Then Response.Write " selected"
   Response.Write ">" & arrOptions(i) & "</option>"
Next

-T

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top