DHTML/Dynamic Dropdowns
Expert: Andrew Hoffman - 1/13/2009
QuestionI am new to web design. What I am trying to do is create a dropdown based on a one field database table. Every time a choice is selected in that dropdown I need the second dropdown to be populated with values from the same table but limited by the value selected. For example lets say I have a table called Place I select the field called Location in the first dropdown, well in the second dropdow should be populated with location codes that match that Location selected. Pleas give an answer in vbscript but java script is acceptable.
Heres the real life code with just the first dropdown completed in an .asp page
<%@ Language=VBScript %>
<LINK rel="stylesheet" type="text/css" href="Style Sheet1.css">
<%'=Session("Conn")%>
<%'=cnly.connection%>
<%
Set cnLy=Server.CreateObject("adodb.Connection")
'cnly.Open Session("appInfo")
cnly.Open Session("Conn")
'cnly.Open Session("Conn")
Set objRS = Server.CreateObject("ADODB.recordset")
sql = "SELECT * FROM [interpstats].[DistrictNames08]"
'Response.Write sql
'responce.write cnly.ConnectionString
%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<META HTTP-EQUIV="REFRESH" CONTENT=300> <!--%'causes a page to refresh after 5 minutes %-->
<meta name="VI60_defaultClientScript" content="VBScript">
<%
If Not isDate(Request.QueryString("D")) then
Else
Session("CurrentDate")=Request.QueryString("D")
Request.QueryString("D")
End if %>
</HEAD>
<BODY>
<A href="Logoff.asp"><img src="Exit.gif" border=0></A><!--log off image -->
<P> <%sTitle="<CENTER><FONT face=verdana><h3>Financial Services LLC<br>Financial Statistics</h3>" & FormatDateTime( Session("CurrentDate"),1)& "</FONT></CENTER>"
Response.write sTitle & "<Center><FONT face=Tahoma size=2 color=red>" & Session("Fname") & " " & Session("Lname") & " - " & Session("Language")& "</Font></Center>"
' prints firstname lastname and language of the user.
%>
<%Response.Write Request.QueryString("D")%>
<FONT face=Tahoma color=#00008b size=3>
<br>
<br>
<br>
<br>
<br>
<br>
<hr>
<form name = "sample" method ="get" action = "calendarrec.asp">
<%objRS.Open sql, cnly%>
<Select name="Id" onchange="this.form.submit();">
<option value = "" selected>Select a District</option>
<%While NOT objRS.EOF%>
<option value ="<%=objRS.Fields(0)%>"><%=objRS.Fields(0)%></option>
<% objRS.MoveNext
Wend
objRS.Close
Set objRS = Nothing
Set cnly=nothing
'Set objConn = Nothing%>
</SELECT>
</form>
AnswerHi mo,
I don't have any VB experience, but found the following link.
http://www.javascriptkit.com/javatutors/selectcontent2.shtml
This example is in JavaScript and is very straightforward. With a little time, you should be able to follow the logic and apply it to your VB page.
Andrew