二級下拉菜單關聯(數據庫版)的簡單方法

 
  <%    
  'Option   Explicit    
  '數據庫結構和上次發表的同樣    
  '二級下拉框連動    
  '    
  '數據庫:    
  'location    
  '表1   loaction   所在地表    
  '   字段    
  '   loactionid   (主鍵)    
  '   loactionname   名字    
  '表2   district   所在的地區表    
  '   字段    
  '   locationid   (主鍵)    
  '   districtid    
  '   districtname    
  %>    
  <html>    
  <head>    
  <title>List</title>    
  <meta   http-equiv="Content-Type"   content="text/html;   charset=gb2312">    
  <%    
   
  dim   rs    
  dim   sql    
  dim   count    
  dim   rs1    
  dim   sql1    
  dim   rs2    
  dim   sql2    
  dim   count2    
   
  sql   =   "select   *   from   district   order   by   locationid   asc"    
  set   rs   =   conn.execute(sql)    
  %>    
  <script   language   =   "JavaScript">    
  var   onecount;    
  onecount=0;    
  subcat   =   new   Array();    
  <%    
  count   =   0    
  do   while   not   rs.eof    
  %>    
  subcat[<%=count%>]   =   new   Array("<%=   trim(rs("districtname"))%>","<%=   trim(rs("locationid"))%>","<%=   trim(rs("districtid"))%>");    
  <%    
  count   =   count   +   1    
  rs.movenext    
  loop    
  rs.close  
  set   rs=nothing    
  %>    
  onecount=<%=count%>;    
   
  function   changelocation(locationid)    
  {    
  document.myform.smalllocation.length   =   0;    
   
  var   locationid=locationid;    
  var   i;    
  document.myform.smalllocation.options[0]   =   new   Option('==所選城市的地區==','');    
  for   (i=0;i   <   onecount;   i++)    
  {    
  if   (subcat[i][1]   ==   locationid)    
  {    
  document.myform.smalllocation.options[document.myform.smalllocation.length]   =   new   Option(subcat[i][0],   subcat[i][2]);    
  }    
  }    
   
  }    
  </script>    
   
   
   
   
   
   
  </head>    
  <body>    
  <form   name="myform"   method="post">    
  題目:<input   type="text"   name="T2"   size="20"><br>    
  來源:<input   type="text"   name="T3"   size="20"><br>    
  分類:<select   name="biglocation"   onChange="changelocation(document.myform.biglocation.options[document.myform.biglocation.selectedIndex].value)"   size="1">    
  <option   selected>請選擇你所在的省份</option>    
  <%    
  sql1   =   "select   *   from   location   order   by   locationname   asc"    
  set   rs1   =   conn.Execute   (sql1)    
  do   while   not   rs1.eof    
  %>    
  <option   value="<%=trim(rs1("locationid"))%>"><%=trim(rs1("locationname"))%></option>    
   
  <%    
  rs1.movenext    
  loop    
  rs1.close    
  set   rs1   =   nothing    
  conn.Close  
  set   conn   =   nothing    
  %>    
  </select>  
   
  <select   name="smalllocation">              
  <option   selected   value="">==所有地區==</option>    
  </select>  
   
   
  <br>    
  關鍵詞:<input   type="text"   name="T4"   size="20"><br>    
  內容:<textarea   rows="9"   name="S1"   cols="51"></textarea>    
  </form>    
   
  </body>    
  </html>  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章