Bytes Expert Newtork: Connect with experts in IT / Business | Expert Topics



Search


Go Back   Programmers Resource > Code Section > ASP Articles
User Name
Password


 
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old 09-16-2003, 12:01 AM
twalter twalter is offline
Registered User
 
Join Date: Jul 2003
Location: Masssachusetts
Posts: 94
Self Submitting drop down with Sub Drop down.

With this code you can create a category and a sub-category drop downs and based on what you select as your category, the sub-category will change.

Self submitting form.

------------------- Code ------------------------

<%@ Language=VBScript %>
<%Option explicit%>
<!--#include file="inc_dbselect.asp"-->
<%

dim strstatus, ShowAction
ShowAction = Request.QueryString("action")
'#################
'View Mode
'#################
Select Case ShowAction
Case ""

strstatus = request.form("category")


Dim oRs, conn, connect, strSQL
set oRs = Server.CreateObject ("adodb.RecordSet")
set conn=server.CreateObject ("adodb.connection")
conn.Open strConnect

%>
<html>
<head>
<title>Example combo box</title>

<script language="javascript">
<!--

function dept_onchange(frmSelect) {
frmSelect.submit();
}

//-->
</script>
</head>
<body>
<% if strstatus <> "" THEN %>
The following was selected : <%=Request.Form ("category")%>
<%
else
Response.write "Select a Category"
END IF%>

<form name="frmSelect" method="Post" action="select.asp">
<SELECT name=category LANGUAGE=javascript onchange="return dept_onchange(frmSelect)">
<option></option>
<%
Set oRs=Server.CreateObject("adodb.recordset")
strSQL = "SELECT * FROM tblcategory where show = 1 ORDER BY categoryname"
oRs.Open strSQL, conn

Do while not oRs.EOF
%>
<option value="<%=oRs("categoryname")%>"<% if request.form("category") = oRs("categoryname") then response.write (" selected")%>><%=oRs("categoryname")%> </option>
<%
oRs.MoveNext
loop
%>
</SELECT>
</form>
<% if strstatus = "" Then
response.write ""
else

dim catname
catname = request.form("category")

%>
<form method="Post" action="select.asp?action=view">
<SELECT name="problemtype">
<%
dim Rs, CN, strSQL2

Set Rs=Server.CreateObject("adodb.recordset")
Set CN = Server.CreateObject("adodb.connection")
strSQL2 = "SELECT * FROM tblsubcategory where category = '"& catname &"' and show = 1 ORDER BY problemname"
CN.Open strConnect
Rs.Open strSQL2, CN

Do while not Rs.EOF
%>
<option value="<%=Rs("problemname")%>"><%=Rs("problemname")%> </option><%=Rs("problemname")%>
<%
Rs.MoveNext
loop
%>
</SELECT>
<table border="0" cellpadding="0" cellspacing="0">
<tr><td><input type="hidden" value="<%=catname%>" name="categoryvalue">
<input type="submit" value="Submit" name="submit">&nbsp;</form></td>
<td><form method="post" action="select.asp"><input type="submit" value=" Reset " name="Reset"></form>
</td></tr></table>

</body>
</html>

<%end if
ShowAction = Request.QueryString("action")
'#################
'View Mode
'#################
'Select Case ShowAction
Case "view"
dim problem, cattype
cattype = request.form("categoryvalue")
problem = request.form("problemtype")
%>
<html>
<head><title>Show results</title></head>
<body>
The following was selected!
<BR>
<%
response.write "<b>Category</b>: " & cattype
response.write "<br>"
response.write "<b>Sub-Category</b>: " & problem

%>
</body>
</html>
<% end select %>

---------------------- End Code ------------------------
__________________
Tom Walter

Last edited by twalter : 03-16-2005 at 11:25 AM.
 


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
Forum Jump



All times are GMT -5. The time now is 08:10 AM.



Powered by: vBulletin Version 3.0.3
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
All content Copyright ©1999 - 2010, Programmers Resource, unless otherwise noted.