Small example of a Drop-down box (Database Edition)

Source: Internet
Author: User
Data | database | dropdown ASP file:
<%@ Language=vbscript%>
<%option explicit%>
<title>List</title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<%
Dim conn
Dim rs
Dim sql
Dim count
Dim rs1
Dim sql1


Set conn = Server. CreateObject ("Adodb.connection")
Conn. Open "Test", "sa", ""


sql = "SELECT * from District ORDER by LocationID ASC"
Set rs = conn.execute (SQL)
%>
<script language = "JavaScript" >
var Onecount;
onecount=0;
subcat = new Array ();
<%
Count = 0
Do as not rs.eof
%>
SUBCAT[&LT;%=COUNT%&GT] = new Array ("<%= Trim (rs (" Districtname "))%>", "<%= Trim (rs (" LocationID "))%>", " <%= Trim (rs ("Districtid"))%> ");
<%
Count = Count + 1
Rs.movenext
Loop
Rs.close
Set rs=nothing
%>
onecount=<%=count%>;

function Changelocation (LocationID)
{
document.myform.smalllocation.length = 0;

var Locationid=locationid;
var i;
Document.myform.smalllocation.options[0] = new Option (' = = = = = = ALL Regions = = = = '];
For (I=0;i < onecount; i++)
{
if (subcat[i][1] = = LocationID)
{
Document.myform.smalllocation.options[document.myform.smalllocation.length] = new Option (subcat[i][0], subcat[i][2 ]);
}
}

}
</script>
<body>
<form name= "MyForm" method= "POST" >
<select name= "Biglocation" onchange= changelocation (document.myform.biglocation.options[ Document.myform.biglocation.selectedindex].value) ">
<%

SQL1 = "SELECT * from Location ORDER by locationname ASC"
Set rs1 = conn. Execute (SQL1)
Do as not rs1.eof
%>
<option value= "<%=trim (rs1 (" LocationID "))%>" ><%=trim (rs1 ("LocationName"))%></option>
<%
Rs1.movenext
Loop
Rs1.close
Set rs1 = Nothing
Conn. Close
Set conn = Nothing
%>
</select>
<select name= "Smalllocation" >
<option selected Value= "" >== All areas ==</option>
</select>
</form>
<script language= "JavaScript" >
Changelocation (Document.myform.biglocation.options[document.myform.biglocation.selectedindex].value);
</script>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.