Infinite cascade of select statements (province | city | County | township | village | ...)

Source: Internet
Author: User
Author: shocknet

Index. asp

Program code:
<HTML>
<Head>
<Title> </title>
<Meta content = "text/html; charset = gb2312" http-equiv = "Content-Type">
<Style type = "text/CSS"> <! --
Font {font-size: 12px}
TD {font-size: 12px}
A {color :# 333399}
A: hover {color: # ff6600}
--> </Style>
<Script language = "JavaScript" type = "text/JavaScript"> <! --
Function funonload (){
Document. All. list_file.src = "jscript_city.asp? Base = 0 & Sele = 0-& ELEM = select01 ";
}

// Pbase series, based on 0,
// Psele is the value of <Option
// Pele is the name of the form at the next level.
Function chgselect (pbase, psele, pelem ){
// After a list is changed. The value of the list after being cleared.
For (I = parseint (pelem. Replace ("select", ""); I <= 5; I ++ ){
VaR TMP = "000" + I;
VaR pelem1 = eval ("document. form1.select" + TMP. substr (TMP. Length-2 ));

Pelem1.length = 1;
Pelem1.selectedindex = 0;
}

// JS uses ASP to obtain database data to update the sublevel list
Document. All. list_file.src = "jscript_city.asp? Base = "+ pbase +" & Sele = "+ psele +" & ELEM = "+ pelem;
}

// --> </SCRIPT>
<SCRIPT id = "list_file" Language = "JavaScript" type = "text/JavaScript" src = ""> </SCRIPT>
</Head>

<Body bgcolor = "# ffffff" leftmargin = "0" topmargin = "2" text = "#333333" onLoad = "funonload ();">
<Form name = "form1">
<Select name = "select01" onchange = "chgselect (1, this. Options [This. selectedindex]. Value, 'select02')">
<Option value = ""> Save... </option>
</SELECT>
<Select name = "select02" onchange = "chgselect (2, this. Options [This. selectedindex]. Value, 'select03')">
<Option value = ""> city... </option>
</SELECT>
<Select name = "select03" onchange = "chgselect (3, this. Options [This. selectedindex]. Value, 'select04 ')">
<Option value = ""> County... </option>
</SELECT>
<Select name = "select04" onchange = "chgselect (4, this. Options [This. selectedindex]. Value, 'select05 ')">
<Option value = ""> Xiang... </option>
</SELECT>
<Select name = "select05">
<Option value = ""> village... </option>
</SELECT>
</Form>
</Body>

'Jscript _ city. asp

Program code:
<%
'Varbase drop-down menu level
'Varsele Database ID of the drop-down menu item selected
'Varelem form name next level

Varbase = request. querystring ("base ")
Varsele = left (request. querystring ("Sele"), instr (request. querystring ("Sele"), "-")-1)
Varelem = request. querystring ("ELEM ")

Vardistname = ""
Varautoid = ""

Set condb = server. Createobject ("ADODB. Connection ")
Condb. Open "driver = {Microsoft Access Driver (*. mdb)}; DBQ =" & server. mappath ("db1.mdb ")

Sqlcommand = "select * From Table1 where filed1 =" & varbase & "and filed2 =" & varsele
Set rsrecord = condb. Execute (sqlcommand)

While not rsrecord. EOF
Vardistname = vardistname & CHR (34) & rsrecord ("filed3") & CHR (34)
Varautoid = varautoid & CHR (34) & rsrecord ("ID") & CHR (34)

Rsrecord. movenext
If not rsrecord. EOF then
Vardistname = vardistname &","
Varautoid = varautoid &","
End if
Wend

Response. Write ("Var vardistname = new array (" & vardistname & ")" & vbcrlf)
Response. Write ("Var varautoid = new array (" & varautoid & ")" & vbcrlf)

Response. Write ("Var varelem = eval (" & CHR (34) & "document. form1." & varelem & CHR (34) & ")" & vbcrlf)

Response. Write ("varelem. Length = vardistname. Length + 1;" & vbcrlf)

Response. Write ("For (VAR I = 0; I <vardistname. length; I ++) {" & vbcrlf)
Response. Write ("varelem. Options [I + 1]. Text = vardistname; "& Vbcrlf)
Response. Write ("varelem. Options [I + 1]. value = varautoid+ '-' + Vardistname; "& Vbcrlf)
Response. Write ("}" & vbcrlf)

Response. Write ("varelem. selectedindex = 0;" & vbcrlf)

%>

Db1.mdb
'-------------------------------------------------
Zeng Xiaoyi village, Huang Shu, Siming, Xiamen, Fujian
Fengze Xihu water head village, Quanzhou, Fujian Province

The above five levels are converted to databases:
'-------------------------------
Id filed1 filed2 filed3
1 0 0 Fujian
2 1 Xiamen
3 1 Quanzhou
4 2 2 Siming
5 3 4 Huang Yu
6 4 5 Zeng Yi Village
7 2 3 fengze
8 3 7 West Lake
9 4 8 shuitou Village
'-------------------------------------------------
Database description:
Id automatic number
The level of the filed1 drop-down menu list. You can set its precision. Is a number)
ID of the last level of filed2 (use a long integer)
Filed3. Length depends on your situation)

This program is passed under IIS4 + win2000p + Access2000.

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.