
09-16-2003, 12:01 AM
|
|
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"> </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.
|