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! |
Poor Requirements Management capabilities in an Enterprise have been linked to excessive project failures, escalating IT costs, and failure to deliver competitive advantage into the marketplace. Join Brianna M Smith from IBM Rational and learn about how successful organizations align IT and Business stakeholders through collaborative processes and tools for effective requirements management, and how an integrated approach across the IT lifecycle can provide unparalleled visibility and traceability to ensure that project teams are delivering on the business vision by "doing the right things" and "doing things right." FREE! Go There Now!
|
|
|
|
Learn to enable users to both rate existing animations and to combine existing animations into new snippets. This is the third in a series of three tutorials that chronicle the building of a site that enables collaborative discussion and animation building using Domino and OpenLaszlo. 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!
|
|
|
|
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!
|
|
|
|
This tutorial shows new users of IBM WebSphere Business Monitor Version 6.0.2 how to perform the "Hello World" equivalent for monitoring business process applications. It is intended to help you get familiar with the capabilities of the product. FREE! Go There Now!
|
|
|
|
Manage, govern, and share services across your organization by using WebSphere Service Registry and Repository. Follow the hands-on exercises to learn how to navigate the Web interface to publish, find, reuse, and update services. FREE! Go There Now!
|
|
|
|
Ken Krugler, co-founder of code search company Krugle, and Laura Merling, vice president of Marketing and Business Development for Krugle, join to talk about the ins and outs of code search and what it means as a new feature for developerWorks users. FREE! Go There Now!
|
|
|
|
Portfolio Management is about effectively managing portfolio value by aligning portfolio investments with business goals. This complimentary e-kit provides a collection of materials that can help you understand how IBM Rational enables and automates best practices for improved governance and clear visibility into portfolio and project performance across the entire IT project lifecycle. FREE! Go There Now!
|
|
|
|
Because access to government information continues to be an area of concern for many U.S. citizens with disabilities, the U.S. government enacted Section 508 of the Rehabilitation Act in 2001 to ensure that government agencies create accessible Web content, enabling all citizens to access the information they need. A fully accessible Web site makes Web content accessible to all individuals, including those with disabilities, who may be accessing Web content via a variety of user agents. Common user agents include standard Web browsers, text-only browsers, assistive devices and mobile devices such as cell phones or personal digital assistants (PDAs). FREE! Go There Now!
|
|
|
|
Get a free trial download of IBM Lotus Forms V3.0 (formerly Workplace Forms), which provides a zero-footprint eForms solution to help you automate and move forms-based business processes off the desktop and onto the Web. With Lotus Forms, you can extend applications beyond the firewall by creating a single electronic form document ready for use in both thick and Web 2.0 thin client format. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |