This demo uses 2 list box's, both are populated by a database. Depending on the selection that is chosen in the first dropdown box, the results will reflect that choice. I've received countless email's how to use 2 listbox's on the same page that are interconnected. I've used frames in this demo, below is both the frames page and the individual pages w/the code.
The main frame page-This page ties all the individual pages together.
<html>
<head>
<title></title>
</head><frameset rows="15%,*" border="0" frameborder="0" framespacing="0">
<frameset cols="20%,*" border="0" frameborder="0" framespacing="0">
<frame name="left" src="frame1.asp">
<frame name="right" src="frame2.asp">
</frameset>
<frame name="bottom" src="bottom.asp">
<noframes>
<p>This page uses frames, but your browser doesn't support them. </p>
</font></body>
</noframes>
</frameset>
</html>
Frame1.asp -This contains the dropdown box that people choose the entry's.
<%
'Good coding practices to declare all your local variables
Dim conn
Dim rs
Dim strconn
Dim DBQValue
' Automatic DataConnection
' This value is generated on the fly
Session("DataConn_ConnectionString") = _
"DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("2listbox.mdb")
' End of Automatic DataConnection
strconn= Session("DataConn_ConnectionString")
set conn= server.createobject("adodb.connection")
set rs= server.createobject("adodb.recordset")
conn.open strconn
strsql="SELECT * FROM dropdown"
rs.open strsql, conn, 2, 2 %>
I do an if statement to determine what browser people are using. If a person is using Internet Explorer this will load this version of the html page. Or below in the Else it will load a dropdown with a submit button. I de-test javascript and could have used client code to submit the form, but I'm prefer this way. It might not be the correct way but what the heck this is free code!
<% If Instr(request.servervariables("http_user_agent"), "MSIE") Then %>
<html>
<head>
<title>Demo Drop Down</title>
</head>
<body>
<script language="vbscript">
sub submitthis
form1.submit
end sub
</script>
<p>Select from the dropdown menu</p><br>
<form ACTION="frame2.asp" METHOD="POST" NAME="form1" target="right">
<p><select ONCHANGE="submitthis" SIZE="1" NAME="one">
<% Do While Not rs.EOF %> <option value="<% = rs("type") %>"> <% = rs("field1") %></option>
<% rs.movenext %><% loop %> </select> <br>
</p>
</form>
</body>
</html>
'This part of the If statement is loaded if the browser is netscape! Sorry but this person selects
'the information and has to click the submit button!
<% Else %>
<html>
<head><title>dude></title></head>
<body>
<p>Select from the dropdown menu</p><br>
<form ACTION="frame2.asp" METHOD="POST" NAME="form1" target="right">
<p><select SIZE="1" NAME="one">
<% Do While Not rs.EOF %> <option value="<% = rs("type") %>"> <% = rs("field1") %></option>
<% rs.movenext %><% loop %> </select> <br>
<input type="submit" name="b1" value="submit"></p>
</form>
</body>
</html>
<% End If %>
<%
rs.close
conn.close
set rs = nothing
set conn = nothing
%>
Frame2.asp - This page shows the resultset that is chosen from the first dropdown box.
<%
'Good coding practices to declare all your local variables
'Does an If statement to see if the request("one") dropdown menu has a value or not
If request("one") <> "" Then
%>
<%
Dim conn
Dim rs
Dim strconn
Dim DBQValue
' Automatic DataConnection
' This value is generated on the fly
Session("DataConn_ConnectionString") = _
"DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("swynk2.mdb")
' End of Automatic DataConnection
strconn= Session("DataConn_ConnectionString")
set conn= server.createobject("adodb.connection")
set rs2= server.createobject("adodb.recordset")
conn.open strconn
strsql="SELECT table1.fielddata FROM table1 WHERE ((table1.fieldkey)='" & request("one") & "');"
rs2.open strsql, conn, 2, 2
%>
<html>
<head>
<title>Load when Empty</title>
</head>
<body>
<form>
<p>The results of what was selected from the first dropdown.</p><br>
<p><select name="d2" size="1">
<% Do While Not rs2.EOF %> <option value="<% = rs2("fielddata") %>"><% = rs2("fielddata") %></option>
<% rs2.movenext %><% loop %> </select><br>
</p>
</form>
</body>
</html>
<%
rs2.close
conn.close
set rs2 = nothing
set conn = nothing
%>
This part gets loaded when the page first loads, when it first loads it is just a blank dropdown box.
<%
Else
%>
<html>
<head>
<title>Load when Empty</title>
</head>
<body>
<form>
<p><select name="d1" size="1">
<option value=""></option>
</select><br>
</p>
</form>
</body>
</html>
<% End If %>
Bottom.asp - This is the major portion of the screen, this is just an example of populating something from the 2nd dropdown menu. This could be instructions or whatever!
<html>
<head>
<title></title>
</head>
<body>
<center>From the 2nd Drop down results could load something to this page<br>I'm still working on this demo so check back for enhancements!
</center>
</body>
</html>
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More ASP Code Articles
More By aspfree
developerWorks - FREE Tools! |
This demonstration gives you an overview of IBM® Rational® Build Forge Express Edition, a global offering that provides a framework to automate and execute software processes. Rational Build Forge provides a software assembly line that can support all of your tools, technologies, and platforms so you can achieve a repeatable, reliable, and traceable build and release process. FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference, featuring Paul Boustany and Mark Krasovich, to speak to the experts about becoming a Rational ClearCase power user. Get a chance to ask your questions and learn tips and tricks for using Rational ClearCase in Agile development FREE! Go There Now!
|
|
|
|
Effective governance for lean development isn’t about command and control. Instead, the focus is on enabling the right behaviors and practices through collaborative and supportive techniques. Hear from Scott Ambler on how it is far more effective to motivate people to do the right thing than it is to force them to do so. Learn how to form a lightweight, collaboration-based framework that reflects the realities of modern IT organizations. FREE! Go There Now!
|
|
|
|
Build secure Web services with transport-level security using IBM Rational Application Developer V7 and IBM WebSphere Application Server V6.1. Follow this three-part series for step-by-step instructions about how to develop Web services and clients, configure HTTP basic authentication, and configure HTTP over SSL (HTTPS). This first part of the series walks you through building a Web service for a simple calculator application. You generate and test two different types of Web services clients: a Java Platform, Enterprise Edition (Java EE) client and a stand-alone Java client. You also handle user-defined exceptions in Web services. FREE! Go There Now!
|
|
|
|
Join us for this web seminar to learn how you can defend your web applications from attack. Learn about the 3 most common web application attacks, including how they occur and what can be done to prevent them. We’ll also discuss manual versus automated approaches for scanning and identifying web application vulnerabilities and how IBM Rational AppScan, an automated vulnerability scanner, can help you automate more of what you are doing manually today. FREE! Go There Now!
|
|
|
|
Learn how to implement a build management system that uses and extends your existing automation technologies. This tutorial shows, step-by-step, how to install and configure IBM Rational Build Forge to manage builds for Jakarta Tomcat from source code. FREE! Go There Now!
|
|
|
|
Learn how Rational Build Forge can extend a simple compile and package build process by adding customization and deployment capability. Go from a manual method to automating: checking for code changes; getting the latest source; compiling and packaging; customizing; copying to and restarting a deployment server; and sending e-mail notification that a new version is available. FREE! Go There Now!
|
|
|
|
Rational Build Forge Express Edition is an automation framework that packages the latest enterprise-grade technologies into a reliable, flexible and robust configuration designed and priced specifically for small to midsize businesses. The new Rational Build Forge Express eKit provides you with valuable resources – including a case study, podcast, demo, and articles – to help you increase staff productivity, compress development cycles and deliver better software, fast. FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference on December 11 at 1:00 pm ET to get tips on building your own plugins with Rational Method Composer. Get your questions answered! FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference on November 29 at 1:00 pm ET to participate in an interactive discusssion with Grady Booch around architecture and reuse. Get your questions answered! FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |