您的位置:首页 > Web前端 > JavaScript

2级菜单联动事例

2005-12-13 21:35 141 查看
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<html>
<head>
<title>2级菜单联动事例</title>
<meta http-equiv="Content-Type" content="text/HTML; charset=gb2312">
 
<script language = "JavaScript">
var onecount;
onecount=0;
subcat = new Array();
 <%
  Class.forName("com.sybase.jdbc2.jdbc.SybDriver");
 Connection con = DriverManager.getConnection("jdbc:sybase:Tds:166.111.1.1:5000/ynds", "sa", "");
 //Connection conn= DriverManager.getConnection(url, "sa","");
 Statement stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
  int count = 0;
 ResultSet rs = stmt.executeQuery("select * from taxempcode order by taxempcode");//读取数据
 while(rs.next())
 {
 String taxempname=rs.getString("taxempname");//转换字符类型
%>
<!--三维数组-->
subcat[<%=count%>] = new Array("<%=taxempname%>","<%=rs.getString("taxorgcode")%>","<%=rs.getString("taxempcode")%>");//产生数组
<%
        count = count + 1;
}
%>
onecount=<%=count%>;
 
function changelocation(id)
{
 //alert(id)
    document.form1.taxempselect.length = 0;
 
    var id=id;
    var i;
    document.form1.taxempselect.options[0] = new Option('选择税务人员','');
    for (i=0;i < onecount; i++)
        {
            if (subcat[i][1] == id)
            {
                document.form1.taxempselect.options[document.form1.taxempselect.length] = new Option(subcat[i][0], subcat[i][2]);
            }       
        }
       
}      
</script>
</head>
<body bgcolor="#FFFFFF">
 
<form name="form1" method="post" action="">
<table width="500"  border="0" cellspacing="0" cellpadding="0" align="center">
  <tr>
    <td width="180" height="20" align="right">选择税务机关:</td>
    <td width="320">
 
  <!--onchange事件的值可以写为:document.form1.taxorgselect.value-->
 
  <select name="taxorgselect"  style="width:250px" onChange="changelocation(document.form1.taxorgselect.options[document.form1.taxorgselect.selectedIndex].value)" size="1">
    <option value="2">请选择税务机关</option>
<%
 rs = stmt.executeQuery("select * from taxorgcode order by taxorgcode");
 while(rs.next())
 {
  String Bname = rs.getString("taxorgname");
  //System.out.println(Bname);
%>
   <option value="<%=rs.getString("taxorgcode")%>"><%=Bname%></option>
<%
}
 rs.close();
 stmt.close();
 con.close();
%>
     </select><br>
    </td>
  </tr>
  <br>
  <tr>
    <td height="20" align="right">选择税务人员:</td>
    <td>
  <select name="taxempselect" style="width:250px">
    <option value="" selected>请选择税务人员</option>
 
     </select>
 
 </td>
  </tr>
  <tr>
    <td height="20" colspan="2" align="center"><input type="submit" name="Submit" value="提交"></td>
  </tr>
<script LANGUAGE="JavaScript">
    //changelocation(document.form1.bigsortselect.options[document.form1.bigsortselect.selectedIndex].value); //将一级分类的value传给changelocation()函数,生成二级分类的列表
</script>
</table>
</form>
 
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息