Code for implementing the Ajax level-2 cascade menu

Source: Internet
Author: User

Client Code : Copy code The Code is as follows: <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> untitled document </title>
</Head>
<SCRIPT type = "text/JavaScript">
VaR XMLHTTP;
VaR A = new array ();
Function createxmlhttprequest (){
If (window. activexobject ){
XMLHTTP = new activexobject ("Microsoft. XMLHTTP ");
}
Else if (window. XMLHttpRequest ){
XMLHTTP = new XMLHttpRequest ();
}
}
Function send_request (){
Createxmlhttprequest ();
VaR year = Document. getelementbyid ("year ");
VaR url = "check_2.php? Page = "+ escape (Year. value );
XMLHTTP. Open ("get", URL, true );
XMLHTTP. onreadystatechange = checkit;
XMLHTTP. Send (null );
}
Function checkit (){
If (XMLHTTP. readystate = 4 ){
If (XMLHTTP. Status = 200 ){
Showchild ();
}
}
}
Function showchild (){
VaR xmldoc = XMLHTTP. responsexml;
VaR content = xmldoc. getelementsbytagname ("city ");
For (VAR I = 0; I <content. length; I ++ ){
Var y = content [I];
A [I] = Y. childnodes [0]. Data;
}
Show1 ();
}
Function show1 (){
VaR OBJ = Document. getelementbyid ("name ");
VaR number = obj. length;
For (var j = obj. Length-1; j> = 0; j --){
OBJ. removechild (obj. childnodes. Item (j ));
}
For (VAR I = 0; I <A. length; I ++ ){
VaR opt = Document. createelement ("option ");
Opt. Text = A [I];
OBJ. Add (OPT );
}
}
</SCRIPT>
<Body>
Year: <select id = "year" onchange = "send_request ()">
<Option value = "0"> select </option>
<Option value = "1"> 1996-2006 </option>
<Option value = "2"> 1986-1995 </option>
<Option value = "3"> 1971-1985 </option>
<Option value = "4"> 1970 or earlier </option>
</SELECT>
Subdirectory: <select id = "name">
<Option value = "0"> select </option>
</SELECT>
</Body>
</Html>

server code: copy Code the code is as follows: header ('content-type: text/xml');
$ xml = " ";
$ year = $ _ Get [" page "];
$ content = $ XML. " ";
if ($ year = "1") {
$ content = $ content. " 1 11 ";
}< br> else if ($ year = '2') {
$ content = $ content. " 2 12 ";
}< br> else if ($ year = '3') {
$ content = $ content. " 3 13 ";
}< br> else if ($ year = '4') {
$ content = $ Content. " 4 14 ";
}< br> echo $ content;
?>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.