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!

How can i make a web page with a combo box showing values from a DB?

Status
Not open for further replies.

ruthcali

Programmer
Apr 27, 2000
470
US
Please help.

I have an Access97 database with a table called tblSystems and fields called SystemID, Name, Date, etc.

How can i make a web page with a combo box showing all the system ids from the table?

Then, selecting a system id will show the user the information for that system id. (such as Name, Date, etc.)

Hui (another tek-tipper)has been trying to help me, but it is not working. And his code has the options hardcoded.

In his example, we are assuming a database with 5 different tables (car, boat, star, house and computer). but i am getting errors.

please help!!



<HTML>
<HEAD>
<META HTTP-EQUIV=&quot;Content-Type&quot;
<TITLE>Query1</TITLE>
<BODY>
<FORM METHOD=&quot;Post&quot; ACTION=&quot;Test.ASP&quot;>
<SELECT name=&quot;type&quot; class='box1'>
<OPTION value='1'>Car</OPTION>
<OPTION value='2'>Boat</OPTION>
<OPTION value='3'>Star</OPTION>
<OPTION value='4'>House</OPTION>
<OPTION value='5'>Computer</OPTION>
</SELECT>
<INPUT TYPE=&quot;Submit&quot; VALUE=&quot;Run Query&quot;>

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


and this is my test.asp:
<% @Language=VBScript %>
<html>
<head>
<title>test</title>
</head>
<body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;>
<% type=Request.Form(&quot;type&quot;)
'Connects to the Access driver and Access database in the Inetpub directory where the database is saved
strProvider = &quot;Driver={Microsoft Access Driver (*.mdb)}; DBQ=E:\Inetpub\'Creates an instance of an Active Server component
set objConn = server.createobject(&quot;ADODB.Connection&quot;)
'Opens the connection to the data store
objConn.Open strProvider
'Instantiate Command object and use ActiveConnection property to
'attach connection to Command object
set cm = Server.CreateObject(&quot;ADODB.Command&quot;)
cm.ActiveConnection = objConn

if (type = 1) then
sqltext = &quot;SELECT * FROM Car&quot;
elseif (type = 2) then
sqltext = &quot;SELECT * FROM Boat&quot;
elseif (type = 3) then
sqltext = &quot;SELECT * FROM Star&quot;
elseif (type = 4) then
sqltext = &quot;SELECT * FROM House&quot;
elseif (type = 5) then
sqltext = &quot;SELECT * FROM Computer&quot;
end if

'set cnn = Server.CreateObject(&quot;ADODB.Connection&quot;)
'cnn.Open &quot;driver={Microsoft Access Driver (*.mdb)};;DBQ=E:\Inetpub\set Results= cnn.Execute(sqltext)
do until Results.eof
Response.Write(Results(&quot;Cost&quot;))
Results.movenext
loop
%>
</form>
</body>
</html> ruth.jonkman@wcom.com
 
This works for me

<p align=&quot;center&quot;><select size=&quot;1&quot; name=&quot;vendorsdrop&quot;>
<option selected value=&quot;mycombo&quot;>Select one</option>
<%
Do while NOT RS.EOF
Response.Write &quot;<Option Value='&quot; & RS(&quot;id&quot;) & &quot;'>&quot;
Response.Write RS(&quot;field&quot;) & &quot;</Option>&quot;
RS.MoveNext
Loop
RS.Close
set RS=nothing
%>
</select></p>
Hope it helps you Tony
(-:
 
Do i need a 2 documents: HTML and ASP?

i am a real beginner and your code looks good, but i just don't know where to type it. In the HTML document? what goes before the code and what goes after the code? what goes in the ASP document?

Please, can you be more specific?

thanks,
ruth ruth.jonkman@wcom.com
 
Just replace from the <Select Name=&quot;type&quot; class='box1'> down and let me know

the code goes in the initial document where you want to display the combo box
YOUR COMBO CODE
<SELECT name=&quot;type&quot; class='box1'>
<OPTION value='1'>Car</OPTION>
<OPTION value='2'>Boat</OPTION>
<OPTION value='3'>Star</OPTION>
<OPTION value='4'>House</OPTION>
<OPTION value='5'>Computer</OPTION>
</SELECT>
<INPUT TYPE=&quot;Submit&quot; VALUE=&quot;Run Query&quot;>

MY COMBO CODE
<p align=&quot;center&quot;><select size=&quot;1&quot; name=&quot;box1&quot;>
<option selected value=&quot;mycombo&quot;>Select one</option>
<%
Do while NOT RS.EOF
Response.Write &quot;<Option Value='&quot; & RS(&quot;id&quot;) & &quot;'>&quot;
Response.Write RS(&quot;field&quot;) & &quot;</Option>&quot;
RS.MoveNext
Loop
RS.Close
set RS=nothing
%>
</select></p>
Tony
(-:
 
Hi Tony,

thanks for writing.

the code i show above in my first post is giving me an error though. so before i update it with your code, i need to make the simple code work. i am getting the following error:
Microsoft VBScript compilation error '800a0400'

Expected statement

/Test.ASP, line 12

type=Request.Form(&quot;type&quot;)

Do you know why i am getting that error? ruth.jonkman@wcom.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top