联动select选项的选定

 联动select的选定

<%@ page language="java" contentType="text/html; charset=gbk"
    pageEncoding="gbk"%>
<%@ page import="java.sql.*"%>
<%@ page import="my.bbs.connections.DBConn"%>
<%@ page import="my.bbs.com.ConvertString" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>添加汽车的品牌种类(//联动select的选定)</title>
<script language="javascript">
<!--
       //先从数据库中取出数据,再构造这个联动的select菜单
 var onecount;
 onecount=0;
 //var j;
  
 subcat = new Array();
 <%
 ConvertString convert = new ConvertString();
 String sql="select ct_id,ct_pid,ct_name from car_type where ct_pid<>0";
 DBConn dbConn = new DBConn();
 Connection conn1 = dbConn.getConn();
 Statement stmt1 = conn1.createStatement();
 ResultSet rs = stmt1.executeQuery(sql);
 int j=0;
 while(rs.next()) {
 %>
 subcat[<%=j%>] = new Array("<%=convert.convertString(rs.getString("ct_name"))%>","<%=rs.getInt("ct_pid")%>","<%=rs.getInt("ct_id")%>");
 <%
 j=j+1;
 }
 if(rs!=null) {
  rs.close();
 }
 if(stmt1!=null) {
  stmt1.close();
 }
 if(conn1!=null) {
  conn1.close();
 }
 %>
 
 onecount=<%=j%>;
 
 function changelocation(locationid)
     {
     document.carTypeForm.ct_id.length = 0;
 
     var locationid=locationid;
     var i;
     document.carTypeForm.ct_id.options[0] = new Option('==分种类==','');
     for (i=0;i < onecount; i++)
         {
             if (subcat[i][1] == locationid)
             {
             document.carTypeForm.ct_id.options[document.carTypeForm.ct_id.length] = new Option(subcat[i][0], subcat[i][2]);
             }       
         }
        
     }   
 
 //-->
</script>
</head>
<body>
<%!
//显示所有的汽车种类
 String str2="";
ConvertString convert = new ConvertString();
 private void showOptions2(Connection conn) {

 Statement stmt = null;
 ResultSet rs = null;
 try {
  stmt = conn.createStatement();
  String sql = "select * from car_type where ct_isparent=1 and ct_pid=0";
  rs = stmt.executeQuery(sql);

  while (rs.next()) {
   str2 += "<option value='" + rs.getInt("ct_id") + "'>"
     + convert.convertString(rs.getString("ct_name")) + "</option>";
  }
 } catch (SQLException e) {
  e.printStackTrace();
 } finally {
  try {
   if (rs != null) {
    rs.close();
    rs = null;
   }
   if (stmt != null) {
    stmt.close();
    stmt = null;
   }
   if(conn!=null) {
    conn.close();
    conn = null;
   }
  } catch (SQLException e) {
   e.printStackTrace();
  }
 }
}

  %>
<%
  DBConn dbConn2 = new DBConn();
  Connection conn = dbConn2.getConn();
  str2="";   //显示种类
  showOptions2(conn);
 

%> 
<form atcion="" method="post" name="carTypeForm">
<table>
 <tr>
    <td>所属种类</td>
    <td><select name="ct_pid" οnchange="changelocation(document.carTypeForm.ct_pid.options[document.carTypeForm.ct_pid.selectedIndex].value)">
         <option value="">==主种类==</option>
         <%=str2%></select></td>
  </tr>
    <tr>
    <td>所属种类系列</td>
    <td><select name="ct_id" ></select></td>
  </tr>
</table>
</form>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值