Implementation code for infinite Rating (asp+ database +js)-Application techniques

Source: Internet
Author: User
Tags chr
Code can be optimized, please optimize according to your needs
Description
First of all the classification read into the JS array (if the amount of data can be a bit cumbersome)
When the selection returns the parent category ID to find the sorted category from the array and display it to the user
Database design (You can add fields to your needs, what categories are classified, and so on)
Field type description
ID Auto Number Record number
Cotename Text category name
Byid number parent category ID (that is, this table ID, the root contact value is 0)

JS part code (named *.asp)
Copy Code code 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= '-Choose-| ';
<%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 as not rs.eof
Response. Write ("id[" &i& "]=" &rs ("id") & ";" &AMP;CHR (10))
Response. Write ("byid[" &i& "]=" &rs ("Byid") & ";" &AMP;CHR (10))
Response. Write ("cotename[" &i& "]= '" &rs ("Cotename") & "';" &AMP;CHR (10))
Rs.movenext
I=i+1
Loop
Else
Response. Write ("id[0]=0;byid[0]=0;cotename[0]= ' no category ';")
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+ "' > Superior classification </option>";}
Alert (length+ '/' +thevalue);
var Lm=document.getelementbyid (' Lmid ');
lm.innerhtml=data+ "</select>";
}
<%conn.close:set conn=nothing%>

calling page code
Copy Code code as follows:

<%
Dim LM
Lm=request ("LM")
If LM=EMPYT or not IsNumeric (LM) then lm=0
%>
<script type= "Text/javascript" src= "*.asp" ></script>
<body onload= "CHECKLM (<%=lm%>)" >
<div id= "Lmid" ></div>
</body>

post-run results
<ptml> <script language= "JavaScript" > 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= '-Choose-| '; Id[0]=1; byid[0]=0; cotename[0]= ' big column 1 '; id[1]=7; byid[1]=0; cotename[1]= ' big column 2 '; id[2]=2; Byid[2]=1; cotename[2]= ' ├ big column 1-1 '; id[3]=3; Byid[3]=1; cotename[3]= ' ├ big column 1-2 '; id[4]=4; Byid[4]=1; cotename[4]= ' ├ big column 1-3 '; id[5]=5; byid[5]=4; cotename[5]= ' ├-big column 1-3-a '; id[6]=6; byid[6]=4; cotename[6]= ' ├-big column 1-3-b '; id[7]=10; byid[7]=6; cotename[7]= ' ├--big column 1-3-b-1 '; id[8]=11; byid[8]=6; cotename[8]= ' ├--big column 1-3-b-2 '; id[9]=12; byid[9]=6; cotename[9]= ' ├--big column 1-3-b-3 '; id[10]=8; byid[10]=7; cotename[10]= ' ├ big column 2-1 '; id[11]=9; byid[11]=7; cotename[11]= ' ├ big column 2-2 '; 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+ "' > Superior classification </option>";} Alert (length+ '/' +thevalue); var lm=document.getelementbyiD (' Lmid '); lm.innerhtml=data+ "</select>"; } </script> <body onload= "CHECKLM (0)" > <div id= "lmid" ></div> </body> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

Database:



Recursion

Copy Code code as follows:

Sub Geta (Theid)

Set Rs=server. CreateObject ("Adodb.recordset")
Dim rs,sql
Sql= "SELECT * from [Db_cote] Where Byid in (" &TheID& ")"
Rs.Open sql,conn,1,1
I=0
If not rs.eof then
Do as not rs.eof
Response. Write (RS ("Cotename") & "<br>")
Call Geta (Rs ("id"))
Rs.movenext
I=i+1
Loop
End If
Rs.close
Set rs=nothing

End Sub

If M=empty then m=0
Call Geta (M)
%>

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.