|
//------------------------------------------------------------
------Ajax section: Get the city's corresponding administrative area, commercial areas, landmarks------
//------------------------------------------------------------
Creating HttpRequest objects
function Createxmlhttprequest () {
var xmlhttp;
if (window. ActiveXObject) {
XMLHTTP = new ActiveXObject ("Microsoft.XMLHTTP")
}else if (window. XMLHttpRequest) {
XMLHTTP = new XMLHttpRequest ();
}
return XMLHTTP;
}
To send an AJAX request, set the value of three elements represented by the type with the return result
Type = 1 (get administrative area)
Type = 2 (Get business area)
Type = 3 (get landmark)
City (urban)
function Ajaxsetobj (type, city)
{
var xmlhttpobj = Createxmlhttprequest ();
Xmlhttpobj.onreadystatechange = function () {
if (xmlhttpobj.readystate = = 4 && xmlhttpobj.status = 200) {
Set HTML elements with results from the background
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);
}
To set HTML elements after an AJAX request
function sethtml (type, txt) {
Setadminarea (TXT);
}
Set up administrative areas
function Setadminarea (TXT) {
var selectobj = document.getElementById ("Selectareacode");
First clear the dropdown box
Clareselectobj (Selectobj);
And then assign a value
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 = "";
}
Clear the dropdown box
function Clareselectobj (selectobj) {
selectobj.innerhtml = "";
}
Ajax Portal
Obj (Owning City text box)
function Doajax () {
var Obj=document.getelementbyid ("Hotelcity");
if (Obj.value = = "") {
Return
}
Set up the Administrative area dropdown list
if (document.getElementById ("Radioadminarea"). Checked)
{
document.getElementById ("Hiddenhotelarea"). value= "1";
Ajaxsetobj (1, obj.value);
}
Set up a business area Drop-down list
if (document.getElementById ("radiobusiness"). Checked)
{
document.getElementById ("Hiddenhotelarea"). value= "2";
Ajaxsetobj (2, Obj.value);
}
//Set landmark multi-select button
if (document.getElementById ("Radioplace"). Checked)
{
document.getElementById (" Hiddenhotelarea "). value=" 3 ";
Ajaxsetobj (3, Obj.value);
}
}
function Setadmintxt (selectobj) {
document.getElementById ("Hiddenhotelarea"). Value = Select Obj.value;
}
Function startrequest (name)
{
var xmlhttpobj = Createxmlhttprequest ();
Xmlhttpobj.onreadystatechange = function () {
if (xmlhttpobj.readystate = 4 && xmlhttpobj.status =) {
Display content
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)
{
Binding City Information
var array=province.split (",");
document.getElementById ("Drpcity"). Options.add (new option ("Please select");
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;
}
|