程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> JSP編程 >> 關於JSP >> jsp中,使用js生成動態的數據庫相關的二級聯動下拉框

jsp中,使用js生成動態的數據庫相關的二級聯動下拉框

編輯:關於JSP

 <html>
<head>
<title>後台產品添加</title>
<meta http-equiv="Content-Type" content="text/HTML; charset=gb2312">
<link href="../INC/Style.Css" rel="stylesheet" type="text/css"> <script language = "JavaScript">
var onecount;
onecount=0;
subcat = new Array();
 <%
 int count = 0;
 rs = Conn.executeQuery("select * from ego_smallsort order by Sid");//讀取數據
while(rs.next())
{
String sname=new String(rs.getString("Sname").getBytes("GBK"),"ISO8859_1");//轉換字符類型
%>
subcat[<%=count%>] = new Array("<%=sname%>","<%=rs.getInt("Bid")%>","<%=rs.getInt("Sid")%>");//產生數組
<%
        count = count + 1;
}
%>
onecount=<%=count%>; function changelocation(id)
    {
    document.form1.smallsortselect.length = 0;      var id=id;
    var i;
    document.form1.smallsortselect.options[0] = new Option(選擇二級分類,);
    for (i=0;i < onecount; i++)
        {
            if (subcat[i][1] == id)
            {
                document.form1.smallsortselect.options[document.form1.smallsortselect.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">
  <select name="bigsortselect" onChange="changelocation(document.form1.bigsortselect.options[document.form1.bigsortselect.selectedIndex].value)" size="1">
    <option value="2">請選擇一級分類</option>
<%
 rs = Conn.executeQuery("select * from ego_bigsort order by Bid");
while(rs.next())
{
 String Bname = new String(rs.getString("Bname").getBytes("GBK"),"ISO8859_1");
 System.out.println(Bname);
%>
   <option value="<%=rs.getInt("Bid")%>"><%=Bname%></option>
<%
}
%>
     </select><br>
    </td>
  </tr>
  <br>
  <tr>
    <td height="20" align="right">選擇二級分類:</td>
    <td>
  <select name="smallsortselect">
    <option value="" selected>請選擇二級分類</option>

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved