//------------------------------------------------------------ //------AJAX部分:擷取城市對應的行政地區、商業地區、地標------ //------------------------------------------------------------ //建立httpRequest對象 function createXMLHttpRequest(){ var xmlhttp; if (window.ActiveXObject){ xmlhttp = new ActiveXObject("Microsoft.XMLHTTP") }else if(window.XMLHttpRequest){ xmlhttp = new XMLHttpRequest(); } return xmlhttp; } //發送ajax請求,用返回結果設定type代表的三個元素值 //type = 1(擷取行政地區) //type = 2(擷取商業地區) //type = 3(擷取地標) //city (所屬城市) function ajaxSetObj( type , city ) { var xmlHttpObj = createXMLHttpRequest(); xmlHttpObj.onreadystatechange = function(){ if (xmlHttpObj.readystate == 4 && xmlHttpObj.status == 200){ //用後台得到的結果設定html元素 setHTML( type , xmlHttpObj.responseText ); } } xmlHttpObj.open("POST","hotelQuery.aspx",false); xmlHttpObj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xmlHttpObj.send( "type=" + type + "&city=" + city ); } //設定ajax請求後的html元素 function setHTML( type , txt ){ setAdminArea( txt ); } //設定行政地區 function setAdminArea( txt ){ var selectObj = document.getElementById( "selectAreaCode" ); //首先清空下拉框 clareSelectObj(selectObj); //再賦值 var tempStrs = txt.split( "|" ); for( var i=0;i<tempStrs.length-1;i++ ){ selectObj.options.add( new Option( tempStrs[i],tempStrs[i] ) ); } selectObj.style.display = ""; } //清空下拉框 function clareSelectObj( selectObj ){ selectObj.innerHTML = ""; } //ajax入口 //obj (所屬城市文字框) function doAjax(){ var obj=document.getElementById("hotelCity"); if( obj.value == "" ){ return; } //設定行政地區下拉式清單 if(document.getElementById("radioAdminArea").checked) { document.getElementById( "hiddenHotelArea" ).value="1"; ajaxSetObj( 1 , obj.value ); } //設定商業地區下拉式清單 if(document.getElementById("radioBusiness").checked) { document.getElementById( "hiddenHotelArea" ).value="2"; ajaxSetObj( 2 , obj.value ); } //設定地標多選按鈕 if(document.getElementById("radioPlace").checked) { document.getElementById( "hiddenHotelArea" ).value="3"; ajaxSetObj( 3 , obj.value ); } } function setAdminTxt( selectObj ){ document.getElementById( "hiddenHotelArea" ).value = selectObj.value; } function StartRequest(name) { var xmlHttpObj = createXMLHttpRequest(); xmlHttpObj.onreadystatechange = function(){ if (xmlHttpObj.readystate == 4 && xmlHttpObj.status == 200){ //顯示內容 for(var j=1;j<document.getElementById("drpcity").options.length;j=j) { document.getElementById("drpcity").options.remove(j); } showCity(xmlHttpObj.responseText); } } var para = name; var aboutPara = "province="+para; xmlHttpObj.open("POST","hotelAdd.aspx",false); xmlHttpObj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xmlHttpObj.send( aboutPara ); } function showCity(province) { //綁定城市資訊 var array=province.split(","); //document.getElementById("drpcity").options.add(new Option("請選擇")); for(var i=0;i<array.length;i++) { var drpCity=document.getElementById("drpcity"); var option=new Option(array[i].toString()); drpCity.options.add(option); } } function getCity(province) { StartRequest(province); } function getCityTxt() { var txtcity=document.getElementById("hotelCity"); var drpCity=document.getElementById("drpcity"); txtcity.value = drpCity.options[drpCity.selectedIndex].text; } |