Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Closed Thread
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 20th, 2003, 07:20 AM
Authorized User
 
Join Date: Oct 2003
Location: , , .
Posts: 89
Thanks: 0
Thanked 0 Times in 0 Posts
Default 2 tables and 2 dropdown lists

I have 2 tables:
SUB TABLE that contains the fields: SUB_ID, CAT_ID, SUB_NAME
CATS TABLE that contains CAT_ID, CAT_NAME

I have a ASP page that contains 2 listboxes. One of the listbox is populated the minute the page is loaded. It receives the CAT_NAME from the CATS table.
The second listbox is supposed to be populated in accordance to what was selected in the CATS listbox.
I am not sure how to do that. I have included the code that i wrote which is wrong:


<%@ Language=VBScript %>


<%'Frame1.asp -This contains the dropdown box that people choose the entry's.
%>
<%
set rsCat = Server.CreateObject("ADODB.Recordset")
rsCat.ActiveConnection = MM_connDUclassified_STRING
rsCat.Source = "SELECT * FROM CATS ORDER BY CAT_DATED DESC"
rsCat.CursorType = 0
rsCat.CursorLocation = 2
rsCat.LockType = 3
rsCat.Open()
rsCat_numRows = 0
%>



<% If Instr(request.servervariables("http_user_agent"), "MSIE") Then %>

<html>

<head>
<title>Demo Drop Down</title>
</head>

<body>
<script language="vbscript">
sub submitthis
'document.write "change"
'form1.submit
document.write "<select>"
end sub
</script>

<p>Select from the dropdown menu</p><br>
<form ACTION="" METHOD="POST" NAME="form1">
<p><select ONCHANGE="submitthis" SIZE="1" NAME="CAT_ID">
<%
While (NOT rsCat.EOF)
%>
                <option value="<%=(rsCat.Fields.Item("CAT_ID").Value)%>" <%if (CStr(rsCat.Fields.Item("CAT_ID").Value) = CStr(rsCat.Fields.Item("CAT_NAME").Value)) then Response.Write("SELECTED") : Response.Write("")%> ><%=(rsCat.Fields.Item("CAT_NAME").Value)%></option>
                <%
  rsCat.MoveNext()
Wend
If (rsCat.CursorType > 0) Then
  rsCat.MoveFirst
Else
  rsCat.Requery
End If
%>
              </select>
</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 METHOD="POST" NAME="form1">
<p><select SIZE="1" NAME="cat_id">
<%
While (NOT rsCat.EOF)
%>
                <option value="<%=(rsCat.Fields.Item("CAT_ID").Value)%>" <%if (CStr(rsCat.Fields.Item("CAT_ID").Value) = CStr(rsCat.Fields.Item("CAT_NAME").Value)) then Response.Write("SELECTED") : Response.Write("")%> ><%=(rsCat.Fields.Item("CAT_NAME").Value)%></option>
                <%
  rsCat.MoveNext()
Wend
If (rsCat.CursorType > 0) Then
  rsCat.MoveFirst
Else
  rsCat.Requery
End If
End If
%>
              </select>

<%
rsCAT.close
'conn.close
set rsCAT = nothing
'set conn = nothing

%>



<%
'Good coding practices to declare all your local variables
'Does an If statement to see if the request("cat_id") dropdown menu has a value or not
If request("cat_id") <> "" Then
%>
<%
set rsSub = Server.CreateObject("ADODB.Recordset")
rsSub.ActiveConnection = MM_connDUclassified_STRING
rsSub.Source = "SELECT SUB_NAME FROM SUBS WHERE ((SUB_name)='" & request("cat_id") & "');"
rsSub.CursorType = 0
rsSub.CursorLocation = 2
rsSub.LockType = 3
rsSub.Open()
rsSub_numRows = 0

%>
<html>
<head>
<title>Load when Empty</title>
</head>
<body>
<form id=form2 name=form2>
<p>The results of what was selected from the first dropdown.</p><br>
<p><select name="d2" size="1">
<% Do While Not rsSub.EOF %> <option value="<% = rsSub("SUB_NAME") %>"><% = rsSub("SUB_NAME") %></option>
<% rsSub.movenext %><% loop %> </select><br>
</p>
</form>
</body>
</html>
<%
rsSubclose
'coM.close
set rsSub = nothing
'set coM = 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 id=form3 name=form3>
<p><select name="d1" size="1">
<option value=""></option>
</select><br>
</p>
</form>
</body>
</html>
<% End If %>























































































































Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Regarding DropDown Lists in Asp.Net venkat_vitala ASP.NET 1.0 and 1.1 Basics 1 January 17th, 2007 09:16 AM
Linked Dropdown Lists contagiouss_blue Beginning VB 6 1 June 8th, 2005 10:35 AM
Page Linking though DropDown Lists mahulda ASP.NET 1.0 and 1.1 Basics 2 April 23rd, 2004 02:58 PM
dependent dropdown lists vivshah VS.NET 2002/2003 1 March 29th, 2004 05:25 PM



All times are GMT -4. The time now is 02:38 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.