二级联动问题。
第一,数据库为
父类da_lei,字段:id,da_name子类xiao_lei,字段:id,xiao_name,da_id代码如下:<script language = "JavaScript">    
var onecount;    
onecount=0;    
subcat = new Array();    
<?    
  $sql = "select * from xiao_lei";    
$result = mysql_query( $sql );    
$count = 0;    
while($res = mysql_fetch_row($result)){    
?>    
subcat[<?=$count?>] = new Array("<?=$res[0]?>","<?=$res[1]?>","<?=$res[2]?>");    
<?    
$count++;    
}    
echo "onecount=$count;"; ?>    
//联动函数    
function changelocation(locationid)    
{    
document.myform.ctype.length = 0;     
var locationid=locationid;    
var i;    
for (i=0;i<onecount;i++)    
       {    
         if (subcat[i][2] == locationid)    
         {     
   
var xiao_id=new Option(subcat[i][0]);            document.myform.ctype.options[document.myform.ctype.length] = new Option(subcat[i][1],subcat[i][0]);    
         
  document.myform.zi_id.options[document.myform.zi_id.length] = new Option(subcat[i][0]);  
 
 }           
       }    
          
}     
  
</script>    
  
<select name="type" onChange="changelocation(document.myform.type.options[document.myform.type.selectedIndex].value)" size="1">    
<option selected value="">请指定主分类</option>    
          
<?php    
$sql = "select * from da_lei";    
$result = mysql_query( $sql );    
while($res = mysql_fetch_row($result)){    
?>    
<option value="<?php echo $res[0];?>"><?php echo $res[0];?>.<?php echo $res[1];?></option>    
   <?php } ?>    
          
   </select>     
   
<select name="ctype"  onChange="changelocation(document.myform.type.options[document.myform.type.selectedIndex].value)"  size="1" >                    
       <option selected value="">请指定小分类</option>    
</select>目前输出效果中,是正确的,不过俺要传值的时候找不到子类id的值。子类数组   
subcat[<?=$count?>] = new Array("<?=$res[0]?>","<?=$res[1]?>","<?=$res[2]?>");    该段代码输出效果源文件为“subcat[0] = new Array("22","党团申请","6");    
    
subcat[1] = new Array("7","企业章程","1");    
    
subcat[2] = new Array("11","计划总结","2");    
    
subcat[3] = new Array("10","工作报告","2");    
    
subcat[4] = new Array("8","财务文书","1");     ”第一个就是子类id
解决了再送分。