用JS做了个省市县三级联动效果可存入数据库的值老不对,有代码,在线等
现在的问题是这样的,当我选好地址后就提交他到数据库中去,可是现在怎么修改提交到数据库中的值都是前面的那些编码,就不是后面的文字。要怎么修改才能正确提交后面的文字呢,望知道的达人,能为小弟排忧解难.........
一下是选择框的代码:
<tr>
<td width="301" height="31" align="right"></td>
<td height="31" colspan="2" align="left">上级产地编码:</td>
<td width="549">省:
<select name="jpr" id="jpr"><option>请选择</option></select>市:<select name="jci" id="ici"><option>请选择</option></select>县(区):<select
name="jco" id="jco"><option>请选择</option></select><script language="javascript" defer="defer">new PCAS
("jpr","jci","jco","","","");</script></td>
</tr>
var city_data="";
city_data="010000|请选择,110000|北京市,110100|市辖区,110101|东城区,110102|西城区,110103|崇文区,110104|宣武区,110105|朝阳区,110106|丰台区,110107|石景山区,110108|海淀区,110109|门头沟区,110111|房山区,110112|通州区,110113|顺义区,110114|昌平区,110115|大兴区,110116|怀柔区,110117|平谷区,110200|县,110228|密云县,110229|延庆县,120000|天津市,120100|市辖区,120101|和平区,120102|河东区,120103|河西区,120104|南开区,120105|河北区,120106|红桥区,120107|塘沽区,120108|汉沽区,120109|大港区,120110|东丽区,120111|西青区,120112|津南区,120113|北辰区,120114|武清区,120115|宝坻区,120200|县,120221|宁河县,120223|静海县,120225|蓟县,130000|河北省,130100|石家庄市,130101|市辖区,130102|长安区,130103|桥东区,130104|桥西区,130105|新华区,130107|井陉矿区,130108|裕华区,130121|井陉县,130123|正定县,130124|栾城县,130125|行唐县,130126|灵寿县,130127|高邑县,130128|深泽县,130129|赞皇县,130130|无极县,130131|平山县,130132|元氏县,130133|赵县,130181|辛集市,130182|藁城市,130183|晋州市,130184|新乐市,130185|鹿泉市,130200|唐山市,130201|市辖区,130202|路南区,130203|路北区,130204|古冶区,130205|开平区,130207|丰南区,130208|丰润区,130223|滦县,130224|滦南县,130225|乐亭县,130227|迁西县,130229|玉田县,130230|唐海县,130281|遵化市,130283|迁安市,130300|秦皇岛市,130301|市辖区,130302|海港区,130303|山海关区,130304|北戴河区,130321|青龙满族自治县,130322|昌黎县,130323|抚宁县,130324|卢龙县,130400|邯郸市,130401|市辖区,130402|邯山区,130403|丛台区,130404|复兴区................等等中间的省略 PCAN = city_data.split(",");
function PCAS() {
this.SelP = document.getElementsByName(arguments[0])[0];
this.SelC = document.getElementsByName(arguments[1])[0];
this.SelA = document.getElementsByName(arguments[2])[0];
this.DefP = this.SelA ? arguments[3] : arguments[2];
this.DefC = this.SelA ? arguments[4] : arguments[3];
this.DefA = this.SelA ? arguments[5] : arguments[4];
this.SelP.PCA = this;
this.SelC.PCA = this;
this.SelP.onchange = function() { PCAS.SetC(this.PCA) };
if (this.SelA) this.SelC.onchange = function() { PCAS.SetA(this.PCA) };
PCAS.SetP(this)
};
PCAS.SetP = function(PCA) {
var p_i = 0;
for (i = 0; i < PCAN.length; i++) {
//document.write(city_arr[i-1].substring(2,6)+"<br>");
if (PCAN[i].substring(2, 6) == "0000") {
PCAPV = PCAN[i].split('|')[0];
PCAPT = PCAN[i].split('|')[1];
PCA.SelP.options.add(new Option(PCAPT, PCAPV));
if (PCA.DefP == PCAPV) PCA.SelP[p_i].selected = true;
p_i++;
}
}PCAS.SetC(PCA)
};
PCAS.SetC = function(PCA) {
PCA.SelC.length = 1;
var c_i=0;
var city1_str = PCA.SelP.value;
var str_city1 = city1_str / 10000;
//alert(str_city1);
for (i = 0; i < PCAN.length; i++) {
if (PCAN[i].substring(0, 2) == str_city1 && PCAN[i].substring(2, 6) != "0000" && PCAN[i].substring(4, 6) == "00") {
PCACV = PCAN[i].split('|')[0];
PCACT = PCAN[i].split('|')[1];
PCA.SelC.options.add(new Option(PCACT, PCACV));
if (PCA.DefC == PCACV) PCA.SelC[c_i+1].selected = true
c_i++;
}
} if (PCA.SelA) PCAS.SetA(PCA)
};
PCAS.SetA = function(PCA) {
PCA.SelA.length = 1;
var a_i=0;
var city2_str = PCA.SelC.value;
var str_city2 = city2_str / 100;
//alert(str_city1);
for (i = 0; i < PCAN.length; i++) {
if (PCAN[i].substring(0, 4) == str_city2 && PCAN[i].substring(4, 6) != "00") {
PCAAV = PCAN[i].split('|')[0];
PCAAT = PCAN[i].split('|')[1];
PCA.SelA.options.add(new Option(PCAAT, PCAAV));
if (PCA.DefA == PCAAV) PCA.SelA[a_i+1].selected = true
a_i++;
}
}
}