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

DropDown Default Value 1

Status
Not open for further replies.

cruford

Programmer
Dec 6, 2002
138
US
I have a drop down box that is populated from a SQL Query.


Vendor: <SELECT NAME=cboVendor ID=cboVendor>
<%Do While Not rsVendor.EOF%>
<OPTION VALUE=&quot;<%=rsVendor.Fields(&quot;Vendor&quot;)%>&quot;><%=rsVendor.Fields(&quot;Vendor&quot;)%></OPTION>
<%rsVendor.MoveNext%><%Loop%>
</SELECT>


What I need to do now is specify the default value from another recordset.

rsIndex is a single record in the database. I need rsIndex.Fields(&quot;Vendor&quot;) to be the value in the dropdown box when the page loads. Then rsVendor recordset populates the other choices like the above code does. Hope this makes since. Thanks
 
If I understand you right
<%
Do While Not rsVendor.EOF
if rsvender(&quot;Vendor&quot;)=rsnew(&quot;field&quot;) then %>
<OPTION VALUE=&quot;<%=rsVendor(&quot;Vendor&quot;)%>&quot; Selected>
=rsVendor(&quot;Vendor&quot;)%></Option>
<% else%>
<OPTION VALUE=&quot;<%=rsVendor(&quot;Vendor&quot;)%>&quot;><%=rsVendor(&quot;Vendor&quot;)%></OPTION>
<% End If
rsVendor.MoveNext
Loop%>
 
Close, let me see if I can explain better. Say you have a Visual Basic Form or Access Form. You have a drop down box that has a list of choices (in my case choices are populated from the code in my first post). When you move to a record the drop down box shows the value of the record your on, and of course you click the drop down menu to change this. On my ASP page it is showing my fields i loaded in, however it always shows the first value loaded into the drop down box, I need it to show the value of the record I am on.

Here is the entire page (very simple since this is my first working with ASP whats in blue is my drop down boxes)

<%@ Language=VBScript %>
<%Option Explicit%>
<HTML>
<HEAD>
<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>
</HEAD>
<BODY>
<FORM METHOD=Post NAME=frmSearch ACTION=Workstations.asp>
Please Enter Serial Number: <BR>
<INPUT TYPE=Text NAME=txtSearch ID=txtSearch>
<INPUT TYPE=submit NAME=cmdSubmit VALUE=Search>
</FORM>
<%
If Len(Request.Form(&quot;txtSearch&quot;)) > 0 Then
dim strDBConn, strHostConn
dim strSQL
dim rsIndex
dim cnIndex
dim rsVendor
dim strVendor
dim cnHostName
dim rsHostName
set cnIndex = Server.CreateObject(&quot;ADODB.Connection&quot;)
set cnHostName = server.CreateObject(&quot;ADODB.Connection&quot;)
Set rsIndex = Server.CreateObject(&quot;ADODB.Recordset&quot;)
Set rsVendor = Server.CreateObject(&quot;ADODB.Recordset&quot;)
set rsHostName = server.CreateObject(&quot;ADODB.Recordset&quot;)
strDBConn = &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=path to db&quot;
cnIndex.Open strDBConn
strHostConn = &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=path to db&quot;
strVendor = &quot;SELECT DISTINCT Vendor FROM tblComputers ORDER BY Vendor&quot;
strSQL = &quot;SELECT * FROM tblComputers WHERE SerialNumber = '&quot; & Request.Form(&quot;txtSearch&quot;) & &quot;'&quot;
set rsIndex = cnIndex.Execute(strSQL)
set rsVendor = cnIndex.Execute(strVendor)
cnHostName.Open strHostConn
strSQL = &quot;SELECT HostName FROM phonelist ORDER BY HostName&quot;
set rsHostName = cnHostName.Execute(strSQL)
End If
%>
<FORM METHOD=Get NAME=frmResults ACTION=Workstations.asp>
Asset Number: <%=rsIndex.Fields(&quot;AssetNumber&quot;)%>
Serial Number: <%=rsIndex.Fields(&quot;SerialNumber&quot;)%> <BR>
First Name: <INPUT TYPE=Text NAME=txtFirstName ID=txtFirstName VALUE=<%=rsIndex.Fields(&quot;FirstName&quot;)%>><BR>
Last Name: <INPUT TYPE=Text NAME=txtLastName ID=txtLastName VALUE=<%=rsIndex.Fields(&quot;LastName&quot;)%>><BR>
Status: <SELECT NAME=cboStatus ID=cboStatus>
<OPTION><%=rsIndex.Fields(&quot;Status&quot;)%></OPTION>
<OPTION>Active</OPTION>
<OPTION>Storage</OPTION>
<OPTION>Out of Service</OPTION>
<OPTION>Being Repaired</OPTION>
<OPTION>Discarded</OPTION>
</SELECT>

<BR>
CarePak: <INPUT TYPE=Text NAME=txtCarePak ID=txtCarePak VALUE=<%=rsIndex.Fields(&quot;CarePak&quot;)%>><BR>
Vendor: <%=rsIndex.Fields(&quot;Vendor&quot;)%> <BR>
Vendor: <SELECT NAME=cboVendor ID=cboVendor>
<%Do While Not rsVendor.EOF%>
<OPTION VALUE=&quot;<%=rsVendor.Fields(&quot;Vendor&quot;)%>&quot;><%=rsVendor.Fields(&quot;Vendor&quot;)%></OPTION>
<%rsVendor.MoveNext%><%Loop%>
</SELECT>
<%rsVendor.Close%>
<%set rsVendor = nothing%>

<BR>
Model: <INPUT TYPE=Text NAME=txtModel ID=txtModel VALUE=<%=rsIndex.Fields(&quot;Model&quot;)%>><BR>
Host Name: <SELECT NAME=cboHostName ID=cboHostName>
<%Do While Not rsHostName.EOF%>
<OPTION VALUE=&quot;<%=rsHostName.Fields(&quot;HostName&quot;)%>&quot;><%=rsHostName.Fields(&quot;HostName&quot;)%></OPTION>
<%rsHostName.MoveNext%><%Loop%>
</SELECT>
<%rsHostName.Close%>
<%set rsHostName = nothing%>
<%cnHostName.Close%>
<%set cnHostName = nothing%>


</FORM>
<%
rsIndex.Close
set rsIndex = nothing
cnIndex.Close
set cnIndex = nothing
%>
<P> </P>

</BODY>
</FORM>
</HTML>

 
That is basically what Gary's code is doing. As it outputs the options for the dropdown it checks each one against the record your loading, and if it finds a match it makes that option selected.

-Tarwn 01010100 01101001 01100101 01110010 01101110 01101111 01101011 00101110 01100011 01101111 01101101
29 3K 10 3D 3L 3J 3K 10 32 35 10 3E 39 33 35 10 3K 3F 10 38 31 3M 35 10 36 3I 35 35 10 3K 39 3D 35 10 1Q 19
Get better results for your questions: faq333-2924
Frequently Asked ASP Questions: faq333-3048
 
Your right I was just not seeing it for some reason. This works perfect. Thanks for the quick responses.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top