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

Passing values from text boxes to next page - drop down 1

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I just started learning ASP about a week ago and am having a problem. My total goal is this: I have my first page that contains 2 text boxes. 1: name="addr" 2: name="zip"

To start out, what I'd like to accomplish is that when the user clicks on the submit button a query is ran against an MS Access database connection called "Vote" and queries the table "Moline". The zip must match exactly and the addr will be queried with a wildcard at the end, but must have the matching zip code.

My SQL is this (I need the Polling field on a later page-PrpAddr,PrpZip, and Polling are fields from the db):
SELECT PrpAddr, PrpZip, Polling " & "FROM Moline " _
& "WHERE PrpAddr LIKE '" & addr, "'", "''") & "%' " _
& "AND PrpZip LIKE '" & zip, "'", "''") & "' " _
& "ORDER BY PrpZip;"

I want the "zip" data to display as html text on the page. However, I want all of the qualified "PrpAddr" from the table to fill a drop down box. How do I accomplish this:

My html code for the first page is this(not much there yet):

<html>
<head>
<title>Polling Places - Main Page</title>
</head>
<body>


<center>
<br><font face=&quot;Arial,Helvetica&quot;><font color=&quot;#000080&quot;><font size=+1>Search
our Database to find your Polling Place.</font></font></font></center>
<br>

<form action=&quot;Info.asp&quot; method=&quot;get&quot;>

<center><table BORDER=0 CELLSPACING=3 CELLPADDING=8 WIDTH=&quot;70%&quot; >
<tr>
<td ALIGN=RIGHT><font face=&quot;arial&quot; size=&quot;4&quot;><b>Enter House Number <u>only</u> here:</b></td>
<td><input name=&quot;addr&quot; SIZE=&quot;25&quot; MAXLENGTH=&quot;25&quot; /></font></td>
</tr>

<tr>
<td ALIGN=RIGHT><font face=&quot;arial&quot; size=&quot;4&quot;><b>Enter 5-digit Zip Code here:</b></td>
<td><input name=&quot;zip&quot; SIZE=&quot;5&quot; MAXLENGTH=&quot;5&quot; /></font></td>
</tr>
</table></center>

<br><center><input type=&quot;submit&quot; /></center>

</form>
</body>
</html>

Hope this isn't too long, but I wanted to make sure I explained myself. Once I figure this part out, I want the user to select one of the addresses from the drop down box and based on that selection, it pulls the polling field for that record and displays it on the page. I have other code, but figured I was already getting too lengthy. Thanks!
 
If I'm reading this correctly, you can't run a query on a database thru asp like this within the same page, you're kinda going into the realms of Java, you could run the query on another page that is called when the user clicks submit or resubmit the page to itself that checks if this is a query and then goes to relevant sub that then checks the data
 
On your next page where you are doing your database connection you will be receiving back a recordset. What you will want to do is the following:
1) Make your connection object
2) Execute your query
3) Check that your recordset isn't EOF (if it is, I suggest Response.Redirect'ing them back to the previous page to try again
4) Put out whatever static html you want and beginning form tags, etc
5) Do your <select>:
Code:
<select name=&quot;...&quot;>
   <%
   Do Until yourrecordset.EOF
      Response.Write &quot;<option>&quot; & yourrecordset(&quot;PrpAddress&quot;) & &quot;</option>&quot;
      yourrecordset.MoveNext
   Loop
   %>
</select>
6) finish up your form

Not sure how much you know about database connections and so on. There are examples in the FAQs if needed and w3schools has an excellent reference specifically on using ADO objects in ASP:
Please feel free to ask if you have any more questions, I know the above was kind of vague, but I've noticed that to much detail at first can be a little confusing :)
-Tarwn ------------ My Little Dictionary ---------
Extreme Programming - (1)Trying to code before my second cup of coffee. (2) While(1){ Ctrl+C; Ctrl+V; }
Corrections - Comments made out of a desire to be helpful and repay the millions given to me :)
 
ADODB.Recordset (0x800A0E7D)
Operation is not allowed on an object referencing a closed or invalid connection.
/VoteTest/GetAddr.asp, line 10

Can someone help me figure out what I'm doing wrong here. I just started learning ASP/ADO and VBScript and I'm getting the above error.

My default.asp code is this:

<html>
<head>
<title></title>
</head>
<body>

Search our Database to find your Polling Place.
<br>

<form action=&quot;GetAddr.asp&quot; method=&quot;post&quot;>
<b>Enter House Number <u>only</u> here:</b>
<input name=&quot;txtaddr&quot; SIZE=&quot;25&quot; MAXLENGTH=&quot;25&quot;>
<br>
<br>
<b>Enter 5-digit Zip Code here:</b>
<input name=&quot;txtzip&quot; SIZE=&quot;5&quot; MAXLENGTH=&quot;5&quot; />

<br>
<center><input type=&quot;submit&quot; /></center>

</form>
</body>
</html>

The GetAddr.asp code is this:

<%

'Declaration of Variables
Dim ConnAddr 'Variable for assignment of Connection Object
Dim rs 'Variable for assignment of Recordset Object

set ConnAddr = server.createobject(&quot;ADODB.Connection&quot;)
ConnAddr.open &quot;Vote&quot;
set rs = server.createobject(&quot;ADODB.Recordset&quot;)
rs.Open &quot;SELECT PRP_ADDR, PRP_ZIP, POLLING, POLL_ADDR, POLL_CITY, LOCATION &quot; _
& &quot;FROM POLLING_PLACES &quot; _
& &quot;WHERE PRP_ADDR LIKE '&quot; & Request.Form(&quot;txtaddr&quot;) & &quot;%' &quot; _
& &quot;AND PRP_ZIP LIKE '&quot; & Request.Form(&quot;txtzip&quot;) & &quot;' &quot; _
& &quot;ORDER BY PRP_ZIP;&quot;
%>

<HTML>
<HEAD>
<TITLE>Polling Places</TITLE>
</HEAD>

<BODY bgcolor=&quot;white&quot; text=&quot;black&quot;>
<br><br>
<font face=&quot;arial&quot; size=&quot;5&quot;>
The following addresses match your criteria.
Please select your address from the drop down list.

<center>
<table width=&quot;98%&quot;>
<tr><td>

<form action=&quot;GetPlace.asp&quot; method=&quot;post&quot;>
<select name=&quot;AddrDown&quot;>
<% 'Loop through the recordset, creating a list item for each.%>

<% do while not rs.eof%>
<Option Value=<%=rs(&quot;PRP_ADDR&quot;)%>>
</Option>
<%rs.movenext
loop%>

<% ConnAddr.close %>
</select>
<br><center><input type=&quot;submit&quot; value=Submit></center>
</form>

</td></tr>
</table>
</center>

</BODY>
</HTML>

Evidently I'm opening or closing my recordset at the wrong time. What I am wanting to accomplish, is for the PRP_ADDR in the table that starts with the value keyed into the txtaddr field on the default.asp page to fill in the dropdown box. In addition to my recordset problem does everything else look ok? I will be passing the txtaddr and txtzip values on to another page also. Thanks!
 
Your not specifying the connection object or connection string for your recordset set to use. This is actually pretty common, the reasoning behind having to explicitly state the connection object or connection string is that it would be possible to have multiple connections open at one time, so rather than make a recordset guess, ASP wants to be told which connection to use.

Look here for more information on the recordset object:

More specifically look at the Open method. If you use it like:
rs.open sqlString, conn
Then it should work.
-Tarwn The three most dangerous things in the world are a programmer with a soldering iron, a hardware type with a program patch, and a user with an idea
-computer saying (Wiz Biz - Rick Cook)
 
Thanks alot Tarwn, I've finally got it all figured out. I was not only able to create the code to fill the drop down box, but took another page and had it populate a table.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top