Implementation Code for unlimited grading (ASP + database + JS)

Source: Internet
Author: User

Code Can be optimized, please optimize according to your needs
Note:
All classes are read and stored in the JS array first (if the data volume is large, it may be a little troublesome)
When selecting, return the parent category ID to find the correct category from the array, and then display it to the user.
Database Design (you can add fields as needed. What category does this classification belong)
Field type description
ID: Record ID
Cotename text category name
Byid number parent category ID (that is, the table ID, the root point value is 0)

Some JS Code (named *. asp)Copy codeThe Code is as follows: <% dim Conn
Set conn = server. Createobject ("ADODB. Connection ")
Conn. connectionstring = "provider = Microsoft. Jet. oledb.4.0 ;"&_
"Data Source =" & server. mappath ("Cote. mdb ")
Conn. Open
%>

Function checklm (thevalue ){
VaR byid = new array ();
VaR cotename = new array ();
VaR id = new array ();
VaR I;
VaR id_s;
VaR byid_s;
VaR cotename_s;
VaR thevalue_r;
VaR DATA = '<select name = "lm" onchange = "checklm (this. Value)">'
Id_s = "| ";
Cotename_s = '-select-| ';
<% Set rs = server. Createobject ("ADODB. recordset ")
SQL = "select * from [db_cote] ORDER BY byid, ID"
Rs. Open SQL, Conn, 1, 1
I = 0
If not Rs. EOF then
Do while not Rs. EOF
Response. Write ("ID [" & I & "] =" & RS ("ID") & ";" & CHR (10 ))
Response. Write ("byid [" & I & "] =" & RS ("byid") & ";" & CHR (10 ))
Response. Write ("cotename [" & I & "] = '" & RS ("cotename") & "';" & CHR (10 ))
Rs. movenext
I = I + 1
Loop
Else
Response. Write ("ID [0] = 0; byid [0] = 0; cotename [0] = 'uncategory ';")
End if
Rs. Close
Set rs = nothing %>
If (thevalue = NULL | thevalue = undefined | thevalue = '') {thevalue = 0 ;}
// If (lmvalue = NULL | lmvalue = undefined | lmvalue = '') {lmvalue = 0 ;}
For (k = 0; k <ID. length; k ++ ){
If (thevalue = ID [k]) {id_s + = thevalue + "|"; cotename_s + = cotename [k] + "|"; thevalue_r = byid [k]; break;} else {thevalue_r = 0 ;}
}
For (I = 0; I <ID. length; I ++ ){
If (thevalue = byid [I]) {
Id_s + = ID [I] + "|"; cotename_s + = cotename [I] + "| ";
}
}
If (id_s = '-1 | '){
For (I = 0; I <ID. length; I ++ ){
If (thevalue = ID [I]) {
Id_s + = ID [I] + "|"; cotename_s + = cotename [I] + "| ";
}
}
}
Id_v = id_s.split ("| ");
Cotename_v = cotename_s.split ("| ");
VaR length = id_v.length-1;
For (j = 0; j <length; j ++ ){
If (thevalue = id_v [J]) {
Data + = "<option value = '" + id_v [J] + "'selected>" + cotename_v [J] + "</option> ";}
Else {
Data + = "<option value = '" + id_v [J] + "'>" + cotename_v [J] + "</option> ";
}
}
If (thevalue! = 0) {Data + = "<option value = '" + thevalue_r + "'> upper-level classification </option> ";}
// Alert (Length + '/' + thevalue );
VaR LM = Document. getelementbyid ('lmid ');
Lm. innerhtml = Data + "</SELECT> ";
}
<% Conn. Close: Set conn = nothing %>

Call Page code
Copy codeThe Code is as follows: <%
Dim LM
Lm = request ("lm ")
If lm = empyt or not isnumeric (LM) Then LM = 0
%>
<HTML>
<SCRIPT type = "text/JavaScript" src = "*. asp"> </SCRIPT>
<Body onload = "checklm (<% = Lm %>)">
<Div id = "lmid"> </div>
</Body>
</Html>

Running result <P>

Related Article

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.