Index. asp Page code
Copy codeThe Code is as follows:
<! -- # Include file = "conn. asp" -->
<%
Set cmd = conn.exe cute ("select bigclassid, bigclassname from bigclass ")
Tempid = cmd ("bigclassid ")
%>
<Select name = "menu" onChange = "getsubcategory (this. value);">
<%
If not cmd. eof then
Do while 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.exe cute ("select * from smallclass where bigclassid =" & tempid)
If not cxd. eof then
Do while 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 class </option> </select>"
Response. write html
End if
%>
</Select>
</Div>
Ajax. js Code
Copy codeThe Code is 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 secondary category </option> </select> ";
Return;
};
Var xmlhttpobj = createxmlhttp ();
If (xmlhttpobj) {// if the object xmlhttpobj is created successfully
Xmlhttpobj. onreadystatechange = handle;
Xmlhttpobj. open ('get', "getsubcategory. asp? Bigclassid = "+ bigclassid +" & number = "+ Math. random (), true); // Add a random number to the get method.
Xmlhttpobj. send (null );
}
}
Function handle () {// client monitoring function
// If (xmlhttpobj. readystate = 4) {// The server completes processing the request
If (xmlhttpobj. status = 200 ){
// Alert ('OK ');
Var html = xmlhttpobj. responseText; // obtain the returned value
Document. getElementById ("subclass"). innerHTML = html;
} Else {
Document. getElementById ("subclass"). innerHTML = "sorry, the requested page has a problem ...";
}
//}
// Else {
// Document. getElementById ("subclass"). innerHTML = xmlhttpobj. readystate; // the server is processing
//}
//}
}
Getsubcategory. asp code
Copy codeThe Code is 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 "invalid parameter"
Response. end
End if %>
<% On error resume next
Set p = conn.exe cute ("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 while 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 class </option> </select>"
End if
P. close
Set p = nothing
Conn. close
Set conn = nothing
Response. write html
Html = ""
End if
%>