_php techniques of two-level linkage menu based on Asp+ajax and database-driven

Source: Internet
Author: User
Index.asp page Code
Copy Code code as follows:

<!--#include file= "conn.asp"-->
<%
Set cmd = Conn.execute ("Select Bigclassid,bigclassname from Bigclass")
Tempid=cmd ("Bigclassid")
%>
<select name= "Menu" onchange= "Getsubcategory (this.value);" >

<%
If not cmd.eof then
Do as not cmd.eof
bigclassid= cmd ("Bigclassid")
Bigclassname = cmd ("Bigclassname")
%>
<option value= "<%=bigclassid%>" ><%=bigclassname%></option>
<%
Cmd.movenext
Loop
End If
Cmd.close
Set cmd = Nothing
%>
</select>
<div id= "Subclass" >
<select name= "submenu" >

<%
Set cxd = Conn.execute ("select * from Smallclass where bigclassid=" & Tempid)
If not cxd.eof then
Do as not cxd.eof
Smallclassid= cxd ("Smallclassid")
Smallclassname = Cxd ("Smallclassname")%>
<option value= "<%=smallclassid%>" ><%=smallclassname%></option>
<%
Cxd.movenext
Loop
Cxd.close
Set cxd = Nothing
Else
html = "<select name= ' smallclassid ' ><option value= ' 0 ' selected> no small category </option></select>"
Response.Write html
End If
%>
</select>
</div>

Ajax.js Code
Copy Code code as follows:

JavaScript Document
function Createxmlhttp ()
{
Xmlhttpobj = false;
try{
Xmlhttpobj = new XMLHttpRequest;
}catch (e) {
try{
Xmlhttpobj=new ActiveXObject ("MSXML2"). XMLHTTP ");
}catch (E2) {
try{
Xmlhttpobj=new ActiveXObject ("Microsoft.XMLHTTP");
}catch (E3) {
Xmlhttpobj = false;
}
}
}
return xmlhttpobj;
}

function Getsubcategory (BIGCLASSID) {
if (bigclassid==0) {
document.getElementById ("Subclass"). Innerhtml= "<select name= ' smallclassid ' ><option value= ' 0 ' selected > select Class Two </option></select> ";
Return
};
var xmlhttpobj = Createxmlhttp ();
if (xmlhttpobj) {//If the object Xmlhttpobj successfully created
Xmlhttpobj.onreadystatechange=handle;
Xmlhttpobj.open (' Get ', ' getsubcategory.asp?bigclassid= ' +bigclassid+ ' &number= ' +math.random (), true);//get method Add a random number.


Xmlhttpobj.send (NULL);
}
}

function handle () {//Client monitoring functions
if (xmlhttpobj.readystate==4) {//server processing request complete
if (xmlhttpobj.status==200) {
Alert (' OK ');
var html = xmlhttpobj.responsetext;//Get return value
document.getElementById ("Subclass"). innerhtml=html;
}else{
document.getElementById ("Subclass"). Innerhtml= "Sorry, there is a problem with the page you requested ...";
}
//}
else{
document.getElementById ("Subclass"). innerhtml=xmlhttpobj.readystate;//Server Processing
//}
//}

}

Getsubcategory.asp Code
Copy Code code as follows:

<% @language = "VBScript" codepage= "936"%>
<!--#include file= "conn.asp"-->
<%
response.charset= "gb2312"
Bigclassid=safe (Request.QueryString ("Bigclassid"))
If bigclassid<> "" Then
Set Re=new regexp
Re.ignorecase=true
Re.global=false
Re.pattern = "^[0-9]{1,3}$"
If not re.test (BIGCLASSID) Then
Response.Write "Illegal parameters"
Response.End
End If%>

<%on Error Resume Next
Set P = Conn.execute ("select * from Smallclass where bigclassid=" & Bigclassid)
If Err Then
Err.Clear
Response.Write "Query Error"
Response.End
End If
If not p.eof then
html = "<select name= ' Select2 ' >" &vbnewline
Do as not p.eof
html = html& "<option value=" &p ("Smallclassid") & "' >" &p ("Smallclassname") & "</option > "&vbnewline
P.movenext
Loop
html = html& "</select>"
Else
html = "<select name= ' smallclassid ' ><option value= ' 0 ' selected> no small category </option></select>"
End If
P.close
Set P = Nothing
Conn.close
Set conn = Nothing
Response.Write html
html = ""
End If
%>

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.