我现在在数据库中建了一张关于部门的表,其中每个部门对应不同的职务
我分别把部门表中的部门名和职务表中的职务名绑定到两个SELECT中,请问如何才能根据前面一个SELECT中的部门名不同,在后面一个SELECT中给出不同的职务名!!!
我分别把部门表中的部门名和职务表中的职务名绑定到两个SELECT中,请问如何才能根据前面一个SELECT中的部门名不同,在后面一个SELECT中给出不同的职务名!!!
调试欢乐多
var aListValue = new Array(2);
aListValue["a"] = new Array("1","2");
aListValue["b"] = new Array("3");var nCurIndex = null;function setupList()
{
if (nCurIndex != document.frmtest.name1.selectedIndex)
{
nCurIndex = document.frmtest.name1.selectedIndex;var sValue = document.frmtest.name1.options[nCurIndex].value;var i;
//remove existing list
for (i=document.frmtest.name2.options.length-1; i >=0 ; i--)
document.frmtest.name2.options.remove(i);for (i=0; i < aListValue[sValue].length;i++)
{
var opt = new Option(aListValue[sValue][i],aListValue[sValue][i]);
document.frmtest.name2.options.add(opt);
} }}
</script><body onload="setupList()">
<form name="frmtest" action="" method="post">
List1: <select name="name1" onchange="setupList()">
<option value="a">a</option>
<option value="b">b</option>
</select><br>
List2:
<select name="name2">
</select><br>
</form>
</body>
<HEAD>
<TITLE>動態下拉菜單</TITLE>
</HEAD>
<BODY>
<form name=selform method=post>
<select name=selmain onchange=sel(this,IdArr,TextArr)>
</select>
<select name=selson>
</select>
</form>
</BODY>
</HTML>
<?
include("include/data_link.php");
//得到IdArr數組,其一維表示主選擇菜單的id,二維表示目標選擇菜單的id
//得到TextArr數組,其一維表示主選擇菜單的text,二維表示目標選擇菜單的text
$R=mysql_query("select * from cateparent order by cateid");
$Num=mysql_num_rows($R);
echo "<script language=javascript>\n";
echo "selform.selmain.length=$Num;\n";
echo "IdArr=new Array();\nTextArr=new Array();\n";
$i=0;
while($PArr=mysql_fetch_array($R)){
echo "IdArr[$i]='$PArr[cateid]';\n";
echo "TextArr[$i]='$PArr[catename]';\n";
echo "selform.selmain.options[$i].value='$PArr[cateid]';\n";
echo "selform.selmain.options[$i].text='$PArr[catename]';\n";
echo "IdArr[$i]=new Array();\n";
echo "TextArr[$i]=new Array();\n";
$m=0;
$SR=mysql_query("select * from cateson where parentid=$PArr[cateid]");
while($SArr=mysql_fetch_array($SR)){
echo "IdArr[$i][$m]='$SArr[id]';\n";
echo "TextArr[$i][$m]='$SArr[sonname]';\n";
$m++;
}
$i++;
}
echo "</script>\n";
?>
<script language=javascript>
sel(selform.selmain,IdArr,TextArr);
function sel(select,IdArray,TextArray)
{
index=select.selectedIndex;
selform.selson.length=IdArray[index].length;
for (n=0;n<IdArray[index].length;n++)
{
var op=selform.selson.options[n];
op.value=IdArray[index][n];
op.text=TextArray[index][n];
}
}
</script>