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