简单的JSP二级联动菜单

本代码通过测试

说明:
一级栏目表。这里是硬编码在文件中了。 
二级栏目表ablum,里面有员工的信息:姓名(albuj_name),id(album_id),所属部门id(type_id)

<%@ include file="../data.jsp" %>
<%@ page contentType="text/html;charset=gb2312" %>
<% request.setCharacterEncoding("gb2312"); %>
<html>
<head>
<title>添加个人资源</title>

<head>
<body bgcolor="#ffffff" text="#000000">

<%
  Rst=null;
  String sql="select * from ablum order by type_id asc";

  Rst=Stmt.executeQuery(sql); 
%>
<script type="text/javascript"> 
  var onecount; 
  onecount=0;
  subcat = new Array();
  <% 
    int count = 0; 
    while(Rst.next()){ 
  %>
  subcat["<%=count%>"] = new    Array('<%=Rst.getString("album_name")%>','<%=Rst.getString("album_id")%>','<%=Rst.getString("type_id")%>');
  <% 
   count++;
  } 
  Rst.close(); 
  %>
  onecount="<%=count%>";

function change(locationid){
  document.myform.albumid.length = 0; 
  var location_id=locationid;
  var length=0;
  var i; 
  for(i=0;i<onecount;i++){
   if (subcat[i][2] == location_id) {
    document.myform.albumid.options[length++] = new Option(subcat[i][0], subcat[i][1]); 
   }
  }


</script>
<%=count %>
<form method="POST" name="myform" action="adminsave.jsp">
  <table>
    <tr> <td>一级分类</td> 
       <TD> <select name="typeId"          onChange="change(document.myform.typeId.options[document.myform.typeId.selectedIndex].value);" size=1> 
         <option selected>==请选一级分类==</option>
         <option value="1">经理室</option>;
         <option value="2">经理室1</option>;
          <option value="3">经理室2</option>;
         <option value="4">经理室3</option>;
         <option value="5">经理室4</option>;
         <option value="6">经理室5</option>;
          <option value="17">经理室6</option>;

         <option value="7">经理室7</option>;
         <option value="8">经理室8</option>;
         <option value="9">经理室9</option>;
         <option value="10">经理室10</option>;
        <option value="11">经理室11</option>;
        <option value="12">经理室12</option>
        <option value="13">经理室13</option>;
        <option value="14">经理室14</option>;
        <option value="15">经理室15</option>;
        <option value="16">经理室16</option>;
        <option value="18">经理室17</option>;
   </select> </TD> 
<TD>选择二级分类</TD> <TD> 
  <select name="albumid"> 
      <option selected>==请选二级分类==</option> 
   </select>

</td></tr></table></forum>
</html>

posted @ 2010-10-12 17:59  chinaifne  阅读(8789)  评论(0编辑  收藏  举报