如何获取省市联动的值并写入数据库?
<body><scriptlanguage="JavaScript"><!--varg_selProvince;varg_selCity;varProvinces=new...
<body>
<script language="JavaScript">
<!--
var g_selProvince;
var g_selCity;
var Provinces=new Array(
new Array("110000","北京市"),
new Array("120000","天津市"),
new Array("130000","河北省"),
……
new Array("710000","台湾省"),
new Array("810000","香港特别行政区"),
new Array("820000","澳门特别行政区")
);
var Citys=new Array(
new Array("110100","北京"),
new Array("120100","天津"),
new Array("130101","石家庄"),
new Array("130201","唐山"),
new Array("130301","秦皇岛"),
……
new Array("542200","泽当镇"),
new Array("542600","八一镇"),
new Array("820000","澳门"),
new Array("810000","香港")
);
function FillProvinces(selProvince)
{
selProvince.options[0]=new Option("请选择","000000");
for(i=0;i<Provinces.length;i++)
{
selProvince.options[i+1]=new Option(Provinces[i][1],Provinces[i][0]);
}
selProvince.options[0].selected=true;
selProvince.length=i+1;
}
function FillCitys(selCity,ProvinceCode)
{
//if the province is a direct-managed city, like Beijing,
//shanghai, tianjin, chongqin,hongkong, macro
//need not "请选择选项"
if(ProvinceCode=="110000"||ProvinceCode=="120000"
||ProvinceCode=="310000"||ProvinceCode=="810000"
||ProvinceCode=="820000"||ProvinceCode=="500000")
count=0;
else
{
selCity.options[0]=new Option("请选择",ProvinceCode);
count=1;
}
for(i=0;i<Citys.length;i++)
{
if(Citys[i][0].toString().substring(0,2)==ProvinceCode.substring(0,2))
{
selCity.options[count]=new Option(Citys[i][1],Citys[i][0]);
count=count+1;
}
}
selCity.options[0].selected=true;
selCity.length=count;
}
function Province_onchange()
{
FillCitys(g_selCity,g_selProvince.value);
}
function InitCitySelect(selProvince,selCity)
{
//alert("begin");
g_selProvince=selProvince;
g_selCity=selCity;
selProvince.onchange=Function("Province_onchange();");
FillProvinces(selProvince);
Province_onchange();
}
function InitCitySelect2(selProvince,selCity,CityCode)
{
InitCitySelect(selProvince,selCity)
for(i=0;i<selProvince.length;i++)
{
if(selProvince.options[i].value.substring(0,2)==CityCode.substring(0,2))
{
selProvince.options[i].selected=true;
}
}
Province_onchange();
for(i=0;i<selCity.length;i++)
{
if(selCity.options[i].value==CityCode)
{
selCity.options[i].selected=true;
}
}
}
//-->
</script>
<form name="profile" method="post" action="post.asp">
<Select id=province size=1 name=province>
<OPTION selected></OPTION>
</Select>
<Select id=city size=1 name=city>
<OPTION selected></OPTION>
</Select>
<SCRIPT language=javascript>
InitCitySelect(document.profile.province,document.profile.city);
</SCRIPT>
<input type="submit">
</form>
</body>
post.asp文件应该怎么写才能把获取的省市写入数据库?
我qq 597542873
我这个联动是实现了,现在是怎么获取选出的值写入数据库access?“向往季后赛”说的我试过了,那样它获取的是id(如选天津的时候获取的是120000),而不是value,我不知道怎么写才能获取value。谢谢 展开
<script language="JavaScript">
<!--
var g_selProvince;
var g_selCity;
var Provinces=new Array(
new Array("110000","北京市"),
new Array("120000","天津市"),
new Array("130000","河北省"),
……
new Array("710000","台湾省"),
new Array("810000","香港特别行政区"),
new Array("820000","澳门特别行政区")
);
var Citys=new Array(
new Array("110100","北京"),
new Array("120100","天津"),
new Array("130101","石家庄"),
new Array("130201","唐山"),
new Array("130301","秦皇岛"),
……
new Array("542200","泽当镇"),
new Array("542600","八一镇"),
new Array("820000","澳门"),
new Array("810000","香港")
);
function FillProvinces(selProvince)
{
selProvince.options[0]=new Option("请选择","000000");
for(i=0;i<Provinces.length;i++)
{
selProvince.options[i+1]=new Option(Provinces[i][1],Provinces[i][0]);
}
selProvince.options[0].selected=true;
selProvince.length=i+1;
}
function FillCitys(selCity,ProvinceCode)
{
//if the province is a direct-managed city, like Beijing,
//shanghai, tianjin, chongqin,hongkong, macro
//need not "请选择选项"
if(ProvinceCode=="110000"||ProvinceCode=="120000"
||ProvinceCode=="310000"||ProvinceCode=="810000"
||ProvinceCode=="820000"||ProvinceCode=="500000")
count=0;
else
{
selCity.options[0]=new Option("请选择",ProvinceCode);
count=1;
}
for(i=0;i<Citys.length;i++)
{
if(Citys[i][0].toString().substring(0,2)==ProvinceCode.substring(0,2))
{
selCity.options[count]=new Option(Citys[i][1],Citys[i][0]);
count=count+1;
}
}
selCity.options[0].selected=true;
selCity.length=count;
}
function Province_onchange()
{
FillCitys(g_selCity,g_selProvince.value);
}
function InitCitySelect(selProvince,selCity)
{
//alert("begin");
g_selProvince=selProvince;
g_selCity=selCity;
selProvince.onchange=Function("Province_onchange();");
FillProvinces(selProvince);
Province_onchange();
}
function InitCitySelect2(selProvince,selCity,CityCode)
{
InitCitySelect(selProvince,selCity)
for(i=0;i<selProvince.length;i++)
{
if(selProvince.options[i].value.substring(0,2)==CityCode.substring(0,2))
{
selProvince.options[i].selected=true;
}
}
Province_onchange();
for(i=0;i<selCity.length;i++)
{
if(selCity.options[i].value==CityCode)
{
selCity.options[i].selected=true;
}
}
}
//-->
</script>
<form name="profile" method="post" action="post.asp">
<Select id=province size=1 name=province>
<OPTION selected></OPTION>
</Select>
<Select id=city size=1 name=city>
<OPTION selected></OPTION>
</Select>
<SCRIPT language=javascript>
InitCitySelect(document.profile.province,document.profile.city);
</SCRIPT>
<input type="submit">
</form>
</body>
post.asp文件应该怎么写才能把获取的省市写入数据库?
我qq 597542873
我这个联动是实现了,现在是怎么获取选出的值写入数据库access?“向往季后赛”说的我试过了,那样它获取的是id(如选天津的时候获取的是120000),而不是value,我不知道怎么写才能获取value。谢谢 展开
2个回答
2008-08-12
展开全部
<script type="text/javascript" src="city.js"></script>
<select name="province" onChange="set_city(this, this.form.city);">
<option value="0">选择省</option>
<option value="北京市">北京市</option>
<option value="上海市">上海市</option>
<option value="天津市">天津市</option>
<option value="重庆市">重庆市</option>
<option value="河北省">河北省</option>
<option value="山西省">山西省</option>
...
</select>
<select name="city" id="citys" >
<option value="0">选择城市</option>
</select>
city.js文件:
cities = new Object();
cities['北京市']=new Array('北京市区', '北京市辖区');
cities['上海市']=new Array('上海市区', '上海市辖区');
cities['天津市']=new Array('天津市区', '天津市辖区');
cities['重庆市']=new Array('重庆市区', '重庆市辖区');
cities['中国台湾']=new Array('中国台湾');
cities['中国香港']=new Array('中国香港');
cities['中国澳门']=new Array('中国澳门');
cities['河北省']=new Array('石家庄', '张家口市', '承德市', '秦皇岛市', '唐山市', '廊坊市', '保定市', '沧州市', '衡水市', '邢台市', '邯郸市');
cities['山西省']=new Array('太原市', '大同市', '朔州市', '阳泉市', '长治市', '晋城市', '忻州地区', '吕梁地区', '晋中市', '临汾地区', '运城地区');
cities['辽宁省']=new Array('沈阳市', '朝阳市', '阜新市', '铁岭市', '抚顺市', '本溪市', '辽阳市', '鞍山市', '丹东市', '大连市', '营口市', '盘锦市', '锦州市', '葫芦岛市');
cities['吉林省']=new Array('长春市', '白城市', '松原市', '吉林市', '四平市', '辽源市', '通化市', '白山市', '延边朝鲜族自治州');
...
function set_city(province, city)
{
var pv, cv;
var i, ii;
pv=province.value;
cv=city.value;
city.length=1;
if(pv=='0') return;
if(typeof(cities[pv])=='undefined') return;
for(i=0; i<cities[pv].length; i++)
{ ii = i+1;
city.options[ii] = new Option();
city.options[ii].text = cities[pv][i];
city.options[ii].value = cities[pv][i];
}}
function cha(){
if (document.myform.u_username.value=="")
{
alert("用户名不能为空!");
}
else
{var str_cha = document.myform.u_username.value;
location.href="cha.aspx?str=" + str_cha;
}}
由于百度限制了输入字数,所以上面的省市我都没写全,你自己去修改就可以了
<select name="province" onChange="set_city(this, this.form.city);">
<option value="0">选择省</option>
<option value="北京市">北京市</option>
<option value="上海市">上海市</option>
<option value="天津市">天津市</option>
<option value="重庆市">重庆市</option>
<option value="河北省">河北省</option>
<option value="山西省">山西省</option>
...
</select>
<select name="city" id="citys" >
<option value="0">选择城市</option>
</select>
city.js文件:
cities = new Object();
cities['北京市']=new Array('北京市区', '北京市辖区');
cities['上海市']=new Array('上海市区', '上海市辖区');
cities['天津市']=new Array('天津市区', '天津市辖区');
cities['重庆市']=new Array('重庆市区', '重庆市辖区');
cities['中国台湾']=new Array('中国台湾');
cities['中国香港']=new Array('中国香港');
cities['中国澳门']=new Array('中国澳门');
cities['河北省']=new Array('石家庄', '张家口市', '承德市', '秦皇岛市', '唐山市', '廊坊市', '保定市', '沧州市', '衡水市', '邢台市', '邯郸市');
cities['山西省']=new Array('太原市', '大同市', '朔州市', '阳泉市', '长治市', '晋城市', '忻州地区', '吕梁地区', '晋中市', '临汾地区', '运城地区');
cities['辽宁省']=new Array('沈阳市', '朝阳市', '阜新市', '铁岭市', '抚顺市', '本溪市', '辽阳市', '鞍山市', '丹东市', '大连市', '营口市', '盘锦市', '锦州市', '葫芦岛市');
cities['吉林省']=new Array('长春市', '白城市', '松原市', '吉林市', '四平市', '辽源市', '通化市', '白山市', '延边朝鲜族自治州');
...
function set_city(province, city)
{
var pv, cv;
var i, ii;
pv=province.value;
cv=city.value;
city.length=1;
if(pv=='0') return;
if(typeof(cities[pv])=='undefined') return;
for(i=0; i<cities[pv].length; i++)
{ ii = i+1;
city.options[ii] = new Option();
city.options[ii].text = cities[pv][i];
city.options[ii].value = cities[pv][i];
}}
function cha(){
if (document.myform.u_username.value=="")
{
alert("用户名不能为空!");
}
else
{var str_cha = document.myform.u_username.value;
location.href="cha.aspx?str=" + str_cha;
}}
由于百度限制了输入字数,所以上面的省市我都没写全,你自己去修改就可以了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询