Re: Recordset used in Select/Option pick list



WynnGIS wrote:
Folks,

In the file parcel_id.asp I need to Query the DB for each DISTINCT
buil and return the results to a Form Select/Option picklist to be
used as input for the next file (parcel_id_process.asp)


This is really an ASP/vbscript question more suited for
microsoft.public.inetserver.asp.general but I will tackle it here:

I know how to gather the DISTINCT buil into a RS and display the
values and I know how to create a Form using Select/Option with
hardcoded values (buil) but I'm not sure how to fit the 2 together.
I want the user to be able to select from the picklist and it would
be good for them to be able to keyin the vaules also.

This is not possible with an HTML dropdown. You will need to provide a
textbox for that. If you wish to validate the entries in the textbox
against the options in the dropdown, then i suggest you go to a
client-side scripting group such as microsoft.public.scripting.jscript
to follow up.


Thanks for your help in advance.

Please refer to code below for parcel_id.asp.



Let's start here. I prefer to put all server-side code at the beginning
of the file (as much as possible, anyways) for easier maintenance, so I
will do that right now. Basically, I am going to use the recordset's
GetString method
(http://msdn.microsoft.com/library/en-us/ado270/htm/mdmthgetstringmethod
(recordset)ado.asp)
to create a string containing the option tags for your select element,
assigning the string to a variable which will be response.written into
the select tag later on.

Also, I prefer short variable names, so I am going to correct that now
as well.

<%
option explicit
dim cn, rs, optHTML
set cn=server.createobject("adodb.connection")
dim dsnstring
dsnstring = "HAZMAT"

'See this: http://www.aspfaq.com/show.asp?id=2126

cn.open dsnstring

Dim sql
sql= "select DISTINCT buil from HMnew"

set rs=cn.execute(sql,,1) '1 = adCmdText
'Always tell ADO the command type - don't make it guess

If not rs.EOF then
optHTML=rs.GetString(,,""">" & vbcrlf & "<option value=""")
optHTML="<option value=""" & _
left(s,len(optHTML) - len(vbcrlf & "<option value="""))
End If
rs.close: set rs=nothing
cn.close: set cn=nothing
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>Location Point ID Input Form</title>
</head>

<BODY BGCOLOR="#DDE2E7" LEFTMARGIN=5 TOPMARGIN=15 TEXT="Black"
LINK="Black" VLINK="Black" ALINK="Black">
<font face="Arial">
<form name="TextForm" action="parcel_id_process.asp" method="GET">
<strong>
Select</strong><br>
Hazmat Location Storage Point:
<select name="buil">
<%=optHTML%>
</select>
<input type="submit" value="Submit" name="submit"><br>
<p>
<img src="images/find_1.gif" width=24 height=24 hspace=0 vspace=0
alt="Search Menu" name="address"
onmousedown="document.location='menu_cf.htm'"
onmouseover="window.status='Search Menu'" BORDER=0 ALIGN="MIDDLE">
<B><A HREF="menu_asp.htm">Search Menu</A></B>
</form>


</body>


--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.


.