My ASP trip-two-level linkage menu production

Source: Internet
Author: User
Tags mdb database connect sql sort access database access
Menu | Linkage Menu | menu | Linkage Menu This problem is actually quite old, but as I have just learned ASP3 months, it is necessary to write down to strengthen their basic knowledge.

Take the most commonly used "provincial and municipal Drop-down list linkage" as an example!

In our production of Web site membership registration information, usually involves filling in their own province/city, if the input or textarea made to fill out the form is not ideal. So most of the sites will choose to link down the form of the list, do not calculate very complex, at the same time it looks very relaxed.

The following are specific practices:

1. Design Database

We use an Access database. First, create a new Access database named Database1.mdb

In the Database1.mdb database, two tables were established for province and city. The specific fields are designed as follows:

Province (province)

Specific fields: id-automatic numbering provincename-province name provinceno-province name Number provinceorder-province sort number

Province Idprovincenameprovinceno Provinceorder 1 Beijing 00 2 Anhui province 11 3 Shandong province 22 4 Jiangsu province 3 3

The following province name is abbreviated.

Design idea: ID is the automatic number of the table, Provincename and Provinceno is necessary, the former is used to store the name of the province, the latter is the necessary field of Contact table City. As for the Provinceorder is used to order the name of the province, control the Drop-down list of the location of the province name, you can omit.

City (cities)

Specific fields: id-AutoNumber cityname-city name cityno-City name Number cityorder-City sort number provinceid-province number

City

Id

CityName

Cityno

Cityorder

Provinceid

1

Beijing

1

1

0

2

Hefei city

2

2

1

3

Wuhu city

3

3

1

4

Anqing city

4

4

1

5

Jinan city

5

5

2

6

Qingdao

6

6

2

The following city name is slightly.

Design idea: The previous four with province table design idea, Provinceid field will province table and city table.

2. Design style and Coding

Two-level linkage style is very simple, in the Dreamweaver 2004 to the design page placed two select Drop-down menu, respectively named Province_select, City_select, they are in the form named Form1.

The encoding requires HTML, VBScript, and JavaScript. The first is to connect the database, we use the common <!--#include file= "conn.asp"--> connection. The code in conn.asp is slightly.

Second, using JavaScript and VBScript to read data from province and city tables and connect Province_select with City_select, this step is the key to the whole process.
The code is as follows:

<script language=javascript>
<%
Dim sql,i,j
'//////////////////////////read out the province table//////////////////////////
Set Rs_province=server.createobject ("Adodb.recordset")
Sql= "SELECT * from Province order by Provinceorder"
Rs_province.open sql,conn,1,1
%>

var selects=[];
selects[' xxx ']=new Array (new option (' Please choose City



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.