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! |
David Barnes, Lead Evangelist for IBM Emerging Internet Technologies will discuss aspects of Web 2.0 that bring value to corporations, academia, and government. He'll also discuss IBM's vision around Web 2.0, including the importance of remixability and consumability. The discussion will culminate with examples of various IBM Software Group solutions you can use to get ahead of the Web 2.0 adoption curve. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial version of Lotus Quickr 8.0, which enables collaboration by transforming the way everyday business content such as documents, rich media, photos, and video can be shared. Lotus Quickr makes it faster and easier to share content of all types (not just documents) within virtual teams. It is designed to make it easier to collaborate across organizational boundaries, while continuing to work within the context of familiar desktop applications. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial version of WebSphere Business Modeler Advanced V6.1.1, IBM’s premier business process modeling and analysis tool for business users that offers process modeling, simulation, and analysis capabilities. IBM WebSphere Business Modeler helps you visualize, understand, and document business processes for continuous improvement. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download the latest trial version of IBM Data Studio V1.1 at no cost. IBM Data Studio is a comprehensive data management solution that helps you effectively design, develop, deploy and manage your data, databases, and database applications throughout the data management life cycle utilizing a consistent and integrated user interface. Unlike other client-side data management solutions that focus on only one aspect of the application lifecycle or database administration, Data Studio complements the Rational Software Delivery platform, providing unparalleled flexibility for a heterogeneous data server environment across platforms. FREE! Go There Now!
|
|
|
|
Download a free trial version of IBM Rational Software Analyzer Developer Edition V7.0 to identify bug defects earlier in the software development cycle. Rational Software Analyzer is an extensible software development solution that reduces the expense of bug-fixes by enabling static analysis code reviews and bug identification very early in the development cycle. FREE! Go There Now!
|
|
|
|
As systems increase in complexity, communication between systems and software teams becomes more and more difficult. Now, there’s a way to improve product quality and communication.<br />Read the “Model Driven Systems Development” white paper to see how. Also included in this kit are more educational white papers, customer examples, tutorials, informative Webcasts, and best practices for designing, building and managing systems.<br /> FREE! Go There Now!
|
|
|
|
This webcast outlines the best practices that must be instituted to gain the maximum benefit from SOA while maintaining high quality of service. Whether you are deploying new applications or managing and monitoring your existing infrastructure, learn how you can ensure high quality of services with SOA based solutions from IBM. All registrants who attend this live Web Seminar will receive complimentary access to a white paper titled “Maintaining QoS in an SOA Environment”. FREE! Go There Now!
|
|
|
|
Learn how to do more with your reusable assets with the free Rational Asset Manager eKit. The eKit includes demos on how Rational Asset Manager tracks and audits your assets in order to utilize them for reuse. Plus you’ll find white papers and a Webcast that discuss the challenges of a Service Oriented Architecture and how Rational Asset Manager can provide quick and effective solutions. FREE! Go There Now!
|
|
|
|
The Eclipse community is constantly working to extend Eclipse's functionality. In this webcast, learn about some of the most important and feature-rich projects under development. From multi-language support to plug-in development, tune in to see what Eclipse is capable of now. FREE! Go There Now!
|
|
|
|
With IBM Rational Systems Development Solution, you can deliver products faster with higher quality. Within this kit, Read the “Model Driven Systems Development” white paper to see how to improve product quality and communication. Then check out the rest of the e-Kit to learn more about important topics that can affect the success of any software project through customer examples, tutorials, informative Webcasts, and best practices for designing, building and managing systems. From start to finish, at every stage in your projects, Rational Systems Development Solution can help your company reach its full potential. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |