Implement unlimited linkage menu stickers without refreshing)

Source: Internet
Author: User
Tags mdb database

Introduction:

This article was originally published by the glacier: the unlimited linkage menu is implemented by the xmhttp, JavaScript, and ASP functions. It consists of three parts: file index.htm, file server. asp, and database data. MDB.

The Code is as follows:

Index.htm

'*************************************** ***********
<! --
Instructions and precautions:
Suppose there are N levels of edge animation menus.
JavaScript function call:
Getresult (objname, nextallobj_str, STR, nextobj)
Parameter description:
Objname: name of the currently changed menu (name)
Nextallobj_str: Connection of all menu names after the menu is changed ("|" used in the middle)
STR: the value of the currently changed menu (this value is the key value of the upper and lower levels of the connection menu in the relevant database table)
Nextobj: Next menu object of the current menu

-->

<Script language = "JavaScript">
Function getresult (objname, nextallobj_str, STR, nextobj)
{
VaR YY = new array ();
YY = nextallobj_str.split ("| ");
For (VAR I = 0; I <yy. length; I ++) clearoptions (eval ("document. All." + YY [I]);
VaR obao = new activexobject ("Microsoft. XMLHTTP ");
Obao. Open ("Post", "server. asp? "+ Objname +" = "+ STR, false );
Obao. Send ();
Buildsel (Unescape (obao. responsetext), nextobj)
}

Function buildsel (STR, Sel)
{
Sel. Options. Length = 0;
If (STR! = ""){
VaR tarrstr = new array ();
Tarrstr = Str. Split ("% $ #@")
Strid = tarrstr [0]
Strname = tarrstr [1]

VaR arrstr1 = new array ();
Arrstr1 = Strid. Split (",");
VaR arrstr2 = new array ();
Arrstr2 = strname. Split (","); // start to build a new select.
For (VAR I = 0; I <arrstr1.length; I ++)
{
Sel. Options [SEL. Options. Length] = New Option (arrstr2 [I], arrstr1 [I])
}
}
 
VaR opobj = New Option ("-- select --","")
Sel. Add (opobj, 0)
Sel. selectedindex = 0
}

Function clearoptions (OBJ ){
For (var j = 0; j <= obj. length; j ++) obj. Remove (0)
VaR opobj = New Option ("-- select --","")
OBJ. Add (opobj, 0)
OBJ. selectedindex = 0

}
</SCRIPT>
<Select name = "sel1" onchange = "getresult (this. Name, 'sel2 | sel3 | sel4 | sel5', this. Value, document. All. sel2)">
<Option value = ""> select </option>
<Option value = "1"> Fujian </option>
<Option value = "2"> Hubei Province </option>
<Option value = "3"> Liaoning </option>
<SELECT>
<Select name = "sel2" onchange = "getresult (this. Name, 'sel3 | sel4 | sel5', this. Value, document. All. sel3)">
<Option value = ""> -- select -- </option>
</SELECT>
<Select name = "sel3" onchange = "getresult (this. Name, 'sel4 | sel5', this. Value, document. All. sel4)">
<Option value = ""> -- select -- </option>
</SELECT>
<Select name = "sel4" onchange = "getresult (this. Name, 'sel5', this. Value, document. All. sel5)">
<Option value = ""> -- select -- </option>
</SELECT>
<Select name = "sel5">
<Option value = ""> -- select -- </option>
</SELECT>
'*************************************** ***********

Server. asp

'*************************************** ***********
<%
''''' Show_backstr function description (example: City field: ID (PK), belong_id (ID of the province), city (city name ))
'''Colname_id: ID (used as the id value associated with the next menu)
''Parameter colname_name: City (note that this is the field name)
'''Table_name: City (note that this is the table name)
''Parameter parentcol: It is belong_id (parent class Id field name)
''Parameter belongparent: that is, sel1 (value from request)
''The returned value is the encrypted value of escape (for example, id1, ID +" 2% $ # @ "+ name1 + name2). Therefore, the client needs to decrypt the encrypted value after obtaining this value.

Dim Conn
Set conn = server. Createobject ("ADODB. Connection ")
Sub opendb (sdbname)
Connstr = "provider = Microsoft. Jet. oledb.4.0; Data Source =" & server. mappath (sdbname)
Conn. Open (connstr)
End sub

Opendb ("data. mdb ")

''' Four menu names passed in
Dim sel1, sel2, sel3, sel4
Sel1 = request ("sel1 ")
Sel2 = request ("sel2 ")
Sel3 = request ("sel3 ")
Sel4 = request ("sel4 ")

If sel1 <> "" Then call show_backstr ("ID", "city", "city", "belong_id", sel1)
If sel2 <> "" Then call show_backstr ("ID", "smallcity", "smallcity", "belong_id", sel2)
If sel3 <> "" Then call show_backstr ("ID", "Node", "Node", "belong_id", sel3)
If sel4 <> "" Then call show_backstr ("ID", "device", "device", "belong_id", sel4)

Sub show_backstr (colname_id, colname_name, table_name, parentcol, belongparent)
Dim arrresult
If belongparent = "" or not isnumeric (belongparent) then
Response. Write escape ("")
Exit sub
End if
SQL = "select" & colname_id & "," & colname_name & "from" & table_name & "where" & parentcol & "=" + belongparent + ""

Set rs = server. Createobject ("ADODB. recordset ")
Rs. Open SQL, Conn, 1, 1

Do until Rs. EOF
Arrresult_id = arrresult_id & RS (colname_id )&","
Arrresult_name = arrresult_name & RS (colname_name )&","
Rs. movenext ()
Loop
If arrresult_id <> "" Then arrresult_id = left (arrresult_id, Len (arrresult_id)-1)
If arrresult_name <> "" then
Arrresult_name = left (arrresult_name, Len (arrresult_name)-1)
Response. Write (escape (arrresult_id & "% $ # @" & arrresult_name ))
End if
End sub

Set conn = nothing

%>
'*************************************** ***********

Data. mdb database description (ACCESS)

'*************************************** ***********

'Database description:
'Table 1: province (province)
'Field name Type
'Id int
'Province varchar (30)

'--- The belong_id of each table below is associated with the ID of the table above ---
'Table 2: City)
'Id int
'Belong_id int
'City varchar (50)
'
'Table 3: smallcity (county)
'Id int
'Belong_id int
'Smallcity varchat (50)
'
'
'Table 4: node (under the node County)
'Id int
'Belong_id int
'Smallcity varchat (50)
'
'Table 5: Device (devices under nodes)
'Id int
'Belong_id int
'Device varchat (50)

'*************************************** ***********

Author: Walking to win: glaciers from: http://www.winsteps.net

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.