$sql_111="select rac_racial,rac_racial_c from racial order by rac_racial"; $R=mysql_query($sql_111); $Num=mysql_num_rows($R); echo "<script language=javascript>\n"; echo "document.form1.racial.length=$Num;\n"; echo "IdArr=new Array();\nTextArr=new Array();\n"; $i=0; while($PArr=mysql_fetch_array($R)) { echo "IdArr[$i]='$PArr[rac_racial]';\n"; echo "TextArr[$i]='$PArr[rac_racial_c]';\n"; echo "document.form1.racial.options[$i].value='$PArr[rac_racial]';\n"; echo "document.form1.racial.options[$i].text='$PArr[rac_racial_c]';\n"; echo "IdArr[$i]=new Array();\n"; echo "TextArr[$i]=new Array();\n"; $m=0; $sql_222="select cls_class,cls_class_c from class where cls_rac_racial='" . $PArr[rac_racial]. "'"; $SR=mysql_query("$sql_222"); while($SArr=mysql_fetch_array($SR)) { echo "IdArr[$i][$m]='$SArr[cls_class]';\n"; echo "TextArr[$i][$m]='$SArr[cls_class_c]';\n"; $m++; } $i++; } echo "</script>\n"; ?> <script language=javascript> sel(document.form1.racial,IdArr,TextArr); function sel(select,IdArray,TextArray) { index=select.selectedIndex; document.form1.cls_class.length=IdArray[index].length; for (n=0;n<IdArray[index].length;n++) { var op=document.form1.cls_class.options[n]; op.value=IdArray[index][n]; op.text=TextArray[index][n]; } } </script>
错误1 form1 => document.form1 错误2 $sql_222="select cls_class,cls_class_c from class where cls_rac_racial=$PArr[rac_racial]";=> $sql_222="select cls_class,cls_class_c from class where cls_rac_racial='" . $PArr[rac_racial]. "'";
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<form name="form1" method="post">
<table width="400" cellspacing="0" cellpadding="0">
<tr>
<td width="25%">
<div align="right">tttt</div>
</td>
<td width="75%">
<select name="racial" id='racial' onchange="sel(form1.racial,IdArr,TextArr)">
</select>
<select name="cls_class" id='cls_class'>
</select>
</td>
</tr>
</table>
</form>
<?php
$link=mysql_connect('localhost','root','123456');
mysql_select_db('wz',$link);
mysql_query("set names 'utf8'");
$sql_111="select rac_racial,rac_racial_c from racial order by rac_racial";
$R=mysql_query($sql_111);
$Num=mysql_num_rows($R);
echo "<script language=javascript>\n";
echo "document.form1.racial.length=$Num;\n";
echo "IdArr=new Array();\nTextArr=new Array();\n";
$i=0;
while($PArr=mysql_fetch_array($R))
{
echo "IdArr[$i]='$PArr[rac_racial]';\n";
echo "TextArr[$i]='$PArr[rac_racial_c]';\n";
echo "document.form1.racial.options[$i].value='$PArr[rac_racial]';\n";
echo "document.form1.racial.options[$i].text='$PArr[rac_racial_c]';\n";
echo "IdArr[$i]=new Array();\n";
echo "TextArr[$i]=new Array();\n";
$m=0;
$sql_222="select cls_class,cls_class_c from class where cls_rac_racial='" . $PArr[rac_racial]. "'";
$SR=mysql_query("$sql_222");
while($SArr=mysql_fetch_array($SR))
{
echo "IdArr[$i][$m]='$SArr[cls_class]';\n";
echo "TextArr[$i][$m]='$SArr[cls_class_c]';\n";
$m++;
}
$i++;
}
echo "</script>\n";
?>
<script language=javascript>
sel(document.form1.racial,IdArr,TextArr);
function sel(select,IdArray,TextArray)
{
index=select.selectedIndex;
document.form1.cls_class.length=IdArray[index].length;
for (n=0;n<IdArray[index].length;n++)
{
var op=document.form1.cls_class.options[n];
op.value=IdArray[index][n];
op.text=TextArray[index][n];
}
}
</script>
错误2
$sql_222="select cls_class,cls_class_c from class where cls_rac_racial=$PArr[rac_racial]";=>
$sql_222="select cls_class,cls_class_c from class where cls_rac_racial='" . $PArr[rac_racial]. "'";