我在php代码中有这个2列表菜单..我的问题是如何在listmenu中获取所选值并将其传递给新查询,以便在第二个listmenu ..中选择要执行的值基于第1个listmenu中的值...下面是我的代码
我有3个名为addpage.php的文件,addpage.html以及更改过程的grade.php
addpage.php和addpage.html
<?php
$level =$template->form_listmenu($lnames,$lvalues,$level,"level",NULL,'width:300px;','onChange="dochange(\'gradedrop\', this.value, \'\',\'\');"',True);
$gnames=array("-- Please Select --");
$gvalues=array("");
$subnames=array("-- Please Select --");
$subvalues=array("");
$booknames=array("Select Books");
$bookvalues=array("");
$grade = $template->form_listmenu($gnames,$gvalues,$grade,"grade",NULL,'width:300px;','',FALSE);
$subject = $template->form_listmenu($subnames,$subvalues,$subject,"subject",NULL,'width:300px;','',FALSE);
$books = $template->form_listmenu($booknames,$bookvalues,$books,"books",NULL,'width:300px;','',FALSE);
?>
addpage.html
<html>
<script language=Javascript>
function Inint_AJAX() {
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {} //IE
try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE
try { return new XMLHttpRequest(); } catch(e) {} //Native Javascript
alert("XMLHttpRequest not supported");
return null;
};
function dochange(src, val, currval , currval1) {
var req = Inint_AJAX();
req.onreadystatechange = function () {
if (req.readyState==4) {
if (req.status==200) {
document.getElementById(src).innerHTML=req.responseText; //retuen value
}
}
};
req.open("GET", "{domain}admin/modules/onlinetools/grades.php?data="+src+"&val="+val+"&currval="+currval+"&currval1="+currval1); //make connection
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1"); // set Header
req.send(null); //send value
}
Grades.php
<?php
///this is the grades.php
$val = $_GET["val"];
$grade = $_GET["currval"];
$subject = $_GET["currval1"];
// Generate book subject table
$sql="SELECT * FROM booksubject WHERE status = '1' AND lid = '".$val.
"' AND subject <> '#N/A' ORDER BY subject ASC";
$query=mysql_query($sql);
$data_num=mysql_num_rows($query);
//$data=mysql_fetch_array($query);
$subnames="-- Please Select --<:>";
$subvalues="<:>";
for($i=1; $i<=$data_num; $i++){
$data=mysql_fetch_array($query);
$subnames.=$subcoma.$data["subject"];
$subvalues.=$subcoma.$data["sid"];
$subcoma="<:>";
}
// Generate book table
$bsql="SELECT * FROM books WHERE subject = '".
$data["sid"]."' ORDER BY title ASC";
$bquery=mysql_query($bsql);
$bdata_num=mysql_num_rows($bquery);
for($b=1; $b<=$bdata_num; $b++){
$bdata=mysql_fetch_array($bquery);
$booknames.=$bookcoma.$bdata["title"].' - '.$bdata["book_code"];
$bookvalues.=$bookcoma.$bdata["bid"];
$bookcoma="<:>";
}
$subnames=explode("<:>",$subnames);
$subvalues=explode("<:>",$subvalues);
$subject = $template->form_listmenu($subnames,$subvalues,$subject,
"subject",NULL,'width:300px;','',False);
echo '<p>'.$subject.'</p>';
$booknames=explode("<:>",$booknames);
$bookvalues=explode("<:>",$bookvalues);
$books = $template->form_listmenu($booknames,$bookvalues,$books,
"books",NULL,'width:300px;','',FALSE);
echo '<p>'.$books.'</p>';
?>