2 DropDown box's to display data, choose one list box and the other on changes to display data!

Contributed by
Rating: 4 stars4 stars4 stars4 stars4 stars / 20
September 01, 1999
Rate this Article:
MEH MEH++


SEARCH ASP FREE
TOOLS YOU CAN USE

advertisement

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>

blog comments powered by Disqus
ASP CODE ARTICLES

- ASP Forms
- ASP: The Beginning
- Getting Remote Files With ASP Continued
- Inbox and Outbox Manipulation in ASP
- Relational DropDownList Using VB.NET
- Ad Tracking URL Hits
- Use ViewState to display one record per page...
- Send Email using ASP.NET formatted in HTML
- ASP File Explorer
- ASP/XML Interview questions by Srivatsan Sri...
- Pressing RETURN won't submit the form
- This shows how you get the TEXT of a combo r...
- Group Data by Adrian Forbes
- Multiple checkbox select sample
- Multiple checkbox select with all values sam...

ASP Web Hosting ASP.Net Web Hosting Windows Web Hosting
 
 
 

ASP Free Forums 
 RSS  Tutorials RSS
 RSS  Forums RSS
 RSS  All Feeds
Site Map 
Request Media Kit
Write For Us Get Paid 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Privacy Policy 
Support 


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 6 - Follow our Sitemap
Most Popular Topics
All ASP.Net Tutorials