Microsoft Access Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft Access Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old October 20th, 2003, 06:22 AM
collie collie is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 5 collie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 12 sec
Reputation Power: 0
Angry 2 tables and 2 dropdown lists

Hi,

I need help please. I have a an access db with 2 tables- subs and cats.
I need two dropdown lists. when the page is loaded the CATS dropdown is populated. when i select a category from CATS i need the other dropdown to be filled with the corresponding categories. However, I am not sure how to do it.
Can someone please help me?
Thanks

<%@ Language=VBScript %>
<!--#include file="Connections/connDUclassified.asp" -->

<%

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
%>

<!--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
'document.write "change"
form1.submit

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 ACTION="" 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

%>

<!-- This 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
%>
<%
set rsSub = Server.CreateObject("ADODB.Recordset")
rsSub.ActiveConnection = MM_connDUclassified_STRING
rsSub.Source = "SELECT SUB_NAME FROM SUBS WHERE ((SUB_NAME.FIELD)='" & 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>
<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>
<p><select name="d1" size="1">
<option value=""></option>
</select><br>
</p>
</form>
</body>
</html>
<% End If %>
Attached Files
File Type: txt class_tables.txt (2.2 KB, 232 views)

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft Access Help > 2 tables and 2 dropdown lists


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT