AJAX # 地址 # 縣市 - 行政區
function GetData(RType,KeyData){
xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
var strURL='GetData.asp?RType=' + RType + '&KeyData=' + KeyData;
xmlhttp.open('POST',strURL,false);
//xmlhttp.Send('&RType=' + RType + '&KeyData=' + KeyData);
xmlhttp.Send(null);
var rc=xmlhttp.responseText;
return rc;
}
function RmOption(RType){
var sltx=window.document.getElementById('slt' + RType);
//移除下一皆的各選項
var oOption;
var ooptcnt=sltx.options.length;
for(var ii=0;ii<ooptcnt;ii++)
{sltx.options[0].removeNode(true);}
}
function GenSlt(RType,rc){
RmOption(RType);
var sltx=window.document.getElementById('slt' + RType);
//split資料
var rca=rc.split(',');
//加入資料選項
for(var idx=0;idx<rca.length;idx++)
{
oOption=window.document.createElement('OPTION');
sltx.options.add(oOption);
oOption.innerText=rca[idx];
oOption.value=rca[idx];
}
}
function sltCity_onchange() {
if(window.event.srcElement.value!='')
{
//設定傳回Server資料
var KeyData;
KeyData=window.document.form1.sltCity.value;
//呼叫xmlhttp啟動Server程式
var rc=GetData('Area',KeyData);
//產生下一階查詢
GenSlt('Area',rc);
}
else
{
RmOption('Area');
}
//移除郵遞區號
window.document.form1.txtPost.value='';
}
function sltArea_onchange() {
if(window.event.srcElement.value!='')
{
//設定傳回Server資料
var KeyData;
KeyData=window.document.form1.sltCity.value + ',' + window.document.form1.sltArea.value;
//呼叫xmlhttp啟動Server程式
var rc=GetData('Post',KeyData);
//產生下一階查詢
// GenSlt('Road',rc);
//輸出郵遞區號
window.document.form1.txtPost.value=rc;
}
else
{
window.document.form1.txtPost.value="";
}
}