Main. php
<Script language = "javascript" src = "initajax. js"> </script> <! -- InitAjax () -->
<Script>
<! --
Function getoption (select1, target)
{
If (select1.value! = 0 ){
// Select1 is the select menu name of the source for data submission.
Var url = "getoption. php? Pid = "+ select1.value; // get the xml url
// Alert (url );
Var ajax = InitAjax ();
Var I = 0;
Ajax. open ("GET", url, true );
Ajax. onreadystatechange = function (){
// If the execution is normal, the returned content is assigned to the specified place.
If (ajax. readyState = 4 & ajax. status = 200 ){
Var obj = ajax. responseXML;
Var properties = obj. getElementsByTagName ("property ");
Var name, value;
Target. options. length = 1;
For (var I = 0, x = 1; I <properties. length; I ++, x ++ ){
Name = properties [I]. getElementsByTagName ("name") [0]. firstChild. nodeValue;
Value = properties [I]. getElementsByTagName ("value") [0]. firstChild. nodeValue;
Target. options [x] = new Option ();
Target. options [x]. text = name;
Target. options [x]. value = value;
}
}
}
Ajax. send (null );
}
}
<Form method = "post" name = "form" action = "index. php">
<Select name = "level1" onchange = "getoption (document. form. level1, document. form. level2);"/>
<Option selected = "ture" value = "0" >== select ==</option>
<?
If ($ nrows> 0 ){
For ($ I = 0; $ I <$ nrows; $ I ++ ){
Echo "<option value =" {$ results [ID] [$ I]} ">{$ results [NAME] [$ I]} </option> ";
}
}
?>
</Select>
<Select name = "level2" onchange = "getoption (document. form. level2, document. form. level3);">
<Option selected = "ture" value = "0" >== select ==</option>
</Select>
Iniajax. js:
Function InitAjax ()
{
Var ajax = false;
Try {
Ajax = new ActiveXObject ("Msxml2.XMLHTTP ");
} Catch (e ){
Try {
Ajax = new ActiveXObject ("Microsoft. XMLHTTP ");
} Catch (E ){
Ajax = false;
}
}
If (! Ajax & typeof XMLHttpRequest! = Undefined ){
Ajax = new XMLHttpRequest ();
}
Return ajax;
}
Getoption. php:
<? Php
If ($ pid = $ _ GET ["pid"])
{
Header ("Content-type: text/xml; charset = GB2312 ");
Echo "<? Xml version = "1.0" encoding = "GB2312"?> ";
Include ("./oracle. inc ");
$ SQL = "select * from AJAXTEST where PARENTID = $ pid ";
// Echo $ SQL;
$ Stmt = ociparse ($ handle, $ SQL );
Ociexecute ($ stmt );
Ocicommit ($ handle );
Ocilogoff ();
$ Nrows = ocifetchstatement ($ stmt, $ results );
Echo "<properties> ";
// Echo "<row >{$ nrows} </row> ";
For ($ I = 0; $ I <$ nrows; $ I ++ ){
Echo "<property> ";
Echo "<value >{$ results [ID] [$ I]} </value> ";
Echo "<name >{$ results [NAME] [$ I]} </name> ";
Echo "</property> ";
}
Echo "</properties> ";
}
?>