Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dropdown change on input of another dropdown??

Status
Not open for further replies.

rlawrason

IS-IT--Management
Oct 26, 2007
1
US
Hi guys, I'm very new to asp and don't even know where to begin to get this to work...here is what I have so far:

Code:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!-- METADATA TYPE="typelib"
              FILE="C:\Program Files\Common Files\System\ado\msado15.dll" -->
<%
Option Explicit

dim objConn, objRS, objRS2, strSQL

Set objConn = Server.CreateObject("ADODB.Connection")
Set objRS = Server.CreateObject("ADODB.Recordset")
Set objRS2 = Server.CreateObject("ADODB.Recordset")

objConn.ConnectionString = Server.MapPath("dropdowns.mdb")
objConn.Provider = "Microsoft.Jet.OLEDB.4.0"
objConn.Open

Sub showDropDownList(c, r, table)
   
    strSQL = "SELECT Teacher FROM " & table & " ORDER BY Teacher ASC"
    Set r = c.Execute(strSQL)
   
    if r.eof = false then
        Response.Write "<form name='form1'>"
        Response.Write "<select name='dropdownlist'>" & vbCrLf
        Response.Write "<option selected='selected' value='blank'>Choose....</option>"
            While r.EOF = false
            Response.Write "<option value='" & r.Fields("Teacher").Value & "'>" & r.Fields("Teacher").Value & "</option>" & vbCrLf
            r.movenext
            Wend
    end if
    Response.Write "</select>" & vbCrLf
   
End Sub

Sub showDropDownList2(c, r, table)
   
    strSQL = "SELECT Student FROM " & table & " WHERE Teacher = 'Teacher1' ORDER BY Student ASC"
    Set r = c.Execute(strSQL)
   
    if r.eof = false then
    Response.Write "<select name='dropdownlist2'>" & vbCrLf
    Response.Write "<option selected='selected' value='blank'>Choose....</option>"
        While r.EOF = false
        Response.Write "<option value='" & r.Fields("Student").Value & "'>" & r.Fields("Student").Value & "</option>" & vbCrLf
        r.movenext
        Wend
    end if
    Response.Write "</select></form>" & vbCrLf
   
End Sub
%>


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<title>Dropdown Testing</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<body>
<h1>Dropdown Testing</h1>

<table width='300' border='0'>
<tr>
    <td width='75'>Teachers:</td>
    <td width='225'><% call showDropDownList(objConn, objRS, "Teachers") %></td>
</tr>
<tr><td width='300'>&nbsp;</td></tr>
<tr>
    <td width='75'>Students:</td>
    <td width='225'><% call showDropDownList2(objConn, objRS2, "Students") %></td>

</body>
</html>

Here's a link to my little test database so you can load up the site:
What I need to do is when the user selects Teacher1 from the first dropdown, I need the second to only display the students in Teacher1's class...the same in Teacher2 case.

I know that to do this, I need to change line 37 to include the variable input from the first dropdown...but I have no idea how to go about doing that. Please help :(
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top