<HTML>
<Head>
<Title> Ajax entry </title>
<Style type = "text/CSS">
<! --
Body {
Font-size: 13px;
Background-color: # e7f3ff;
}
FORM {
Padding: 0px; margin: 0px;
}
Input {
Border-bottom: 1px solid # 007eff;/* underline */
Font-family: Arial, Helvetica, sans-serif;
Color: # 007eff;
Background: transparent;
Border-top: none;
Border-left: none;
Border-Right: none;
}
P {
Margin: 0px;
Padding: 2px 2px 2px 10px;
Background: url(icon.gif) No-repeat 0px 10px;/* Add a small icon */
}
-->
</Style>
<Script language = "JavaScript">
VaR XMLHTTP;
Function createxmlhttprequest (){
If (window. activexobject ){
XMLHTTP = new activexobject ("Microsoft. XMLHTTP ");
}
Else if (window. XMLHttpRequest ){
XMLHTTP = new XMLHttpRequest ();
}
}
// Create an XMLHTTPRequest object
Createxmlhttprequest ();
Function callserver (){
// Obtain the data in the form
VaR city = Document. getelementbyid ("city"). value;
VaR state = Document. getelementbyid ("state"). value;
// Return if not specified
If (city = NULL) | (city = "") return;
If (State = NULL) | (State = "") return;
// Link to the server and get the code automatically. In this example, the server is not linked.
VaR url = "getzipcode. php? City = "+ escape (city) +" & State = "+ escape (State );
// Open the link
XMLHTTP. Open ("get", URL, true );
// Tell the server what to do after running (it may take five or five hours). The updatepage function is triggered here.
XMLHTTP. onreadystatechange = updatepage;
// Send the request
XMLHTTP. Send (null );
}
// Process Server Response
Function updatepage (){
If (XMLHTTP. readystate = 4 ){
VaR response = XMLHTTP. responsetext;
Document. getelementbyid ("zipcode"). value = response;
}
}
</SCRIPT>
</Head>
<Body>
<Form>
<P> City: <input type = "text" name = "city" id = "city" size = "25" onchange = "callserver ();"> </P>
<P> country: <input type = "text" name = "state" id = "state" size = "25" onchange = "callserver ();"> </P>
<P> code: <input type = "text" name = "zipcode" id = "city" size = "5"> </P>
</Form>
</Body>
</Html>