Do multiple drop-down lists?

Source: Internet
Author: User

How do I make a drop-down list of provinces?

1 Get the Select object var selprov=getel ("Prov");//Get Object

2, traverse the Select Object selprov.options[n]=opt;

3, get the Province object

var prov=new Array (2);
prov["Shaanxi"]=["Xi ' an", "Weinan", "Xianyang", "Hanzhong"];
prov["Henan"]=["Zhengzhou", "Luoyang", "Kaifeng"];
prov["Sichuan"]=["Chengdu", "Guangyuan"];

4, Traverse Province object

For (var p in Prov) {
var opt=new option (P);//Create an Option object
selprov.options[n]=opt;
n++;

How do I get a drop-down list of cities?

1 Get the Select object var selcity=getel ("City")

2, traverse the Select Object selcity.options[i]=opt;

3, get the City object var citys=prov[p];

4, traverse the city object

for (Var i=0;i<citys.length;i++) {
var opt=new Option (Citys[i]);
selcity.options[i]=opt;
}

All code:

<select id= "Prov" onchange= "selcity (this);" >
</select> Province
<select id= "City" ></select>
<script>
var prov=new Array (2);
prov["Shaanxi"]=["Xi ' an", "Weinan", "Xianyang", "Hanzhong"];
prov["Henan"]=["Zhengzhou", "Luoyang", "Kaifeng"];
prov["Sichuan"]=["Chengdu", "Guangyuan"];

function Getel (ID) {
return document.getElementById (ID);
}

Initialize Province
function Initprov () {
var Selprov=getel ("Prov");//Get Object
var n=0;
For (var p in Prov) {
var opt=new option (P);//Create an Option object
selprov.options[n]=opt;
n++;
}
Selcity (Selprov);
}

function Selcity (o) {
var P=o.value;
var citys=prov[p];
var Selcity=getel ("City");//Get HTML Object
Clear
selcity.options.length=0;

for (Var i=0;i<citys.length;i++) {
var opt=new Option (Citys[i]);
selcity.options[i]=opt;
}
}


Initprov ();
</script>
</body>

Do multiple drop-down lists?

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.