A strong and practical Ajax level-2 linkage menu (with demo and source attached)ProgramPackage and download)
I used the level-2 linkage menu when I was working on the background the other day. I was not satisfied after I went online for a long time. This was not the case, but it was the case. Sometimes I couldn't return it when I selected it. really depressing.
Later, I saw someone using Ajax to write an unlimited classification (OX, Haha, I don't understand it .). I thought that I could not use Ajax in the background. Although it is slower than using JavaScript, it is practical. strong .. no error occurs. If a category is selected, the status of the unselected category is null. haha.
File directory:
Main Code As follows:
Index. asp
Copy code The Code is as follows: <% @ Language = "VBScript" codePage = "936" %>
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" C/>
<Title> Ajax second-level linkage by ah Feng </title>
<Script language = "JavaScript" src = "Js. js"> </SCRIPT>
</Head>
<Body>
<H2> <a href = "http://yeahdown.com/"> Ajax secondary linkage by ah peak </a> </H2>
<! -- # Include file = "iconn. asp" -->
<%
Set afeng = conn. Execute ("select bigclassid, bigclassname from bigclass ")
%>
<Form ID = "form1" name = "form1" method = "Post" Action = "">
<Div id = "bigclass" style = "float: Left">
<Select name = "select">
<Option value = "0"> select a level-1 Category </option>
<% If not afeng. EOF then
Do while not afeng. EOF
Bigclassid = afeng ("bigclassid ")
Bigclassname = afeng ("bigclassname") %>
<Option value = "<% = bigclassid %>"> <% = bigclassname %> </option>
<% Afeng. movenext
Loop
End if
Afeng. Close
Set afeng = nothing
Conn. Close
Set conn = nothing %>
</SELECT>
</Div>
<Div id = "subclass" style = "float: Left"> <select name = "select2">
<Option value = "0"> Select secondary category </option>
</SELECT>
</Div>
</Form>
</Body>
</Html>
Getsubcategory. asp file: Copy code The Code is as follows: <%
Response. charset = "gb2312" 'sets the original UTF-8 character set
Bigclassid = safe (request. querystring ("bigclassid") 'invalid character filtering
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 %>
<! -- # Include file = "iconn. asp" -->
<% 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 = 'smallclassid '>" & 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
%>
Iconn. asp file:Copy codeThe Code is as follows: <%
Set conn = server. Createobject ("ADODB. Connection ")
DB = "$ # yeahdown.com $ %. asp"
C & server. mappath (db)
On Error resume next
Conn. Open connstr
If err then
Err. Clear
Response. Write "<Div id =" "error"> database connection error </div>"
Response. End
End if
Function safe (STR)
If isnull (STR) then
Safe = ""
Exit Function
End if
STR = Replace (STR, CHR (0), "", 1,-1, 1)
STR = Replace (STR, ",", 1,-1, 1)
STR = Replace (STR, "<", "<", 1,-1, 1)
STR = Replace (STR, ">", ">", 1,-1, 1)
STR = Replace (STR, "script", "script", 1,-1, 0)
STR = Replace (STR, "script", "script", 1,-1, 0)
STR = Replace (STR, "script", "script", 1,-1, 0)
STR = Replace (STR, "script", "script", 1,-1, 1)
STR = Replace (STR, "object", "object", 1,-1, 0)
STR = Replace (STR, "object", "object", 1,-1, 0)
STR = Replace (STR, "object", "object", 1,-1, 0)
STR = Replace (STR, "object", "object", 1,-1, 1)
STR = Replace (STR, "applet", "applet", 1,-1, 0)
STR = Replace (STR, "applet", "applet", 1,-1, 0)
STR = Replace (STR, "applet", "applet", 1,-1, 0)
STR = Replace (STR, "applet", "applet", 1,-1, 1)
STR = Replace (STR ,"[","[")
STR = Replace (STR, "]", "]")
STR = Replace (STR, "," ", 1,-1, 1)
STR = Replace (STR, "=", "=", 1,-1, 1)
STR = Replace (STR, "'", "'' ", 1,-1, 1)
STR = Replace (STR, "select", "select", 1,-1, 1)
STR = Replace (STR, "execute", "execute", 1,-1, 1)
STR = Replace (STR, "EXEC", "EXEC", 1,-1, 1)
STR = Replace (STR, "Join", "Join", 1,-1, 1)
STR = Replace (STR, "Union", "Union", 1,-1, 1)
STR = Replace (STR, "where", "where", 1,-1, 1)
STR = Replace (STR, "insert", "insert", 1,-1, 1)
STR = Replace (STR, "delete", "delete", 1,-1, 1)
STR = Replace (STR, "Update", "Update", 1,-1, 1)
STR = Replace (STR, "like", "like", 1,-1, 1)
STR = Replace (STR, "Drop", "Drop", 1,-1, 1)
STR = Replace (STR, "CREATE", "CREATE", 1,-1, 1)
STR = Replace (STR, "RENAME", "RENAME", 1,-1, 1)
STR = Replace (STR, "Count", "Count", 1,-1, 1)
STR = Replace (STR, "CHR", "CHR", 1,-1, 1)
STR = Replace (STR, "mid", "mid", 1,-1, 1)
STR = Replace (STR, "truncate", "truncate", 1,-1, 1)
STR = Replace (STR, "nchar", "nchar", 1,-1, 1)
STR = Replace (STR, "char", "char", 1,-1, 1)
STR = Replace (STR, "alter", "alter", 1,-1, 1)
STR = Replace (STR, "cast", "cast", 1,-1, 1)
STR = Replace (STR, "exists", "exists", 1,-1, 1)
STR = Replace (STR, CHR (13), "<br>", 1,-1, 1)
Safe = Replace (STR, "'", "'' ", 1,-1, 1)
End Function
%>
Last Js. js Copy code The Code is as follows: function createxmlhttp ()
{
Xmlhttpobj = false;
Try {// create objects one by one. Ah, it would be nice if the standards can be unified ..
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. Open ('get', "getsubcategory. asp? Bigclassid = "+ bigclassid +" & number = "+ math. Random (), true); // Add a random number to the get method.
Xmlhttpobj. Send (null );
Xmlhttpobj. onreadystatechange = function () {// 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 = "loading, please wait..."; // server processing
}
}
}
}
Package File Download