Linkage between the JS provincial and municipal drop-down lists
Source: Internet
Author: User
1. Define the urban data array
2. Get the selected Province
3. Obtain the location of the current province in the city array.
4. Obtain the prefecture-level cities under the jurisdiction of the current Province
5. Fill in the city drop-down list
----------
Example Code As follows: < Html >
< Head >
< Title > </ Title >
< Script Language = "JavaScript" Type = "Text/JavaScript" >
// Define a city data array
Cityarray = New Array ();
Cityarray [ 0 ] = New Array ( " Henan " , " Zhengzhou City | Kaifeng City | Luoyang City | Pingdingshan City | Anyang city | hebi city | Xinxiang City | Jiaozuo City | Puyang City | xuchang city | Luohe City | Sanmenxia City | Nanyang City | Shangqiu City | Xinyang City | Zhoukou City | Zhumadian City | Jiyuan City " );
Cityarray [ 1 ] = New Array ( " Yunnan Province " , " Kunming City | Dali City | Qujing City | Yuxi city | Zhaotong City | Chuxiong City | Honghe city | Wenshan city | Simao City | Xishuangbanna city | Baoshan City | Dehong city | Lijiang City | Nujiang city | diqing city | Lincang City " );
Cityarray [ 2 ] = New Array ( " Others " , " Others " );
Function Getcity (currprovince)
{
// Current Province
VaR Currprovince = Currprovince;
VaR I, J, K;
// Clear city drop-down list
Document. All. selcity. Length = 0 ;
For (I = 0 ; I < Cityarray. length; I ++ )
{
// Obtain the location of the current province in the city array.
If (Cityarray [I] [ 0 ] = Currprovince)
{
// Obtain the prefecture-level cities under the jurisdiction of the current Province
Tmpcityarray = Cityarray [I] [ 1 ]. Split ( " | " )
For (J = 0 ; J < Tmpcityarray. length; j ++ )
{
// Fill city drop-down list
Document. All. selcity. Options [document. All. selcity. Length] = New Option (tmpcityarray [J], tmpcityarray [J]);
}
}
}
}
</ Script >
</ Head >
< Body >
< Form ID = "Form1" >
< Select ID = "Selprovince" Onchange = "Getcity (this. Options [This. selectedindex]. Value )" >
< Option Value = "" > -Select- </ Option >
< Option Value = "Henan Province" > Henan </ Option >
< Option Value = "Yunnan Province" > Yunnan Province </ Option >
< Option Value = "Others" > Others </ Option >
</ Select >
< Select ID = "Selcity" >
< Option > -City- </ Option >
</ Select >
</ Form >
</ Body >
</ Html >
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