AllExperts > DHTML 
Search      
DHTML
Volunteer
Answers to thousands of questions
 Home · More DHTML Questions · Answer Library  · Encyclopedia ·
More DHTML Answers
Question Library

Ask a question about DHTML
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Andrew Hoffman
Expertise
I can field just about any question within this topic ranging from JavaScript to CSS, the two ingredients of DHTML. I`m very interested in the W3C and its validation rules for HTML, XHTML, and CSS, and enjoy answering questions of this type as well. I detest sleep and respond at all hours of the day or night.


Experience
Experience in the area
I've been working with DHTML and CSS for 7 years now and build/maintain websites of my own that implement DHTML navigation.

What I'm doing now
My contract with Microsoft has ended and I am working for myself once again. Please contact me for any front-end work at antibland@gmail.com

 
   

You are here:  Experts > Computing/Technology > HTML/XML > DHTML > Dynamic Dropdowns

DHTML - Dynamic Dropdowns


Expert: Andrew Hoffman - 1/13/2009

Question
I 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>


Answer
Hi 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

Add to this Answer   Ask a Question


 
User Agreement | Privacy Policy | Kids' Privacy Policy | Help
Copyright  © 2008 About, Inc. AllExperts, AllExperts.com, and About.com are registered trademarks of About, Inc. All rights reserved.