main.php
<script language= "javascript" src= "Initajax.js" ></script><!--initajax ()-->
<script>
<!--
function GetOption (select1,target)
{
if (select1.value!=0) {
Select1 is the source of the submitted data, select Vegetable Single-name
The var url = "Getoption.php?pid=" +select1.value;//gets the URL of the XML
alert (URL);
var ajax = Initajax ();
var i = 0;
Ajax.open ("Get", url, True);
Ajax.onreadystatechange = function () {
If the execution is normal, assign the returned content 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" >=== Choice ===</option>
?
if ($nrows >0) {
for ($i =0; $i < $nrows; $i + +) {
echo "<option value=" {$results [id][]} ">{$results [name][$i]}</option>";
}
}
?>
</select>
<select name= "Level2" onchange= "getoption (DOCUMENT.FORM.LEVEL2,DOCUMENT.FORM.LEVEL3);" >
<option selected= "ture" value= "0" >=== Choice ===</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>";
}
?>