它山之石可以攻玉

键盘上的生活
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

ASP新闻栏目切换+JS

Posted on 2007-03-28 11:44  陈达辉  阅读(827)  评论(0编辑  收藏  举报

<%
dim rs
dim sql
dim count
set rs=server.createobject("adodb.recordset")
sql = "select * from kml_sclass"
rs.open sql,conn,1,1
%>
<script language = "JavaScript">
var onecount;
onecount=0;
subcat = new Array();
        <%
        count = 0
        do while not rs.eof
        %>
subcat[<%=count%>] = new Array("<%= trim(rs("sclassname"))%>","<%= trim(rs("bclassid"))%>","<%= trim(rs("sclassid"))%>");
        <%
        count = count + 1
        rs.movenext
        loop
        rs.close
        %>
onecount=<%=count%>;

function changelocation(locationid)
    {
    document.myform.sclassid.length = 0;

    var locationid=locationid;
    var i;
    for (i=0;i < onecount; i++)
        {
            if (subcat[i][1] == locationid)
            {
              document.myform.sclassid.options[document.myform.sclassid.length] = new Option(subcat[i][0], subcat[i][2]);
            }       
        }
       
    }   
</script>

</head>
<body>
<br>
<form name="myform" method="post" action="?action=addsave">
<table width="80%"  border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#CCCCCC">
  <tr bgcolor="#F6F6F6">
    <td height="25" colspan="2"><div align="center"><strong>修 改 新 闻</strong></div></td>
  </tr><tr bgcolor="#F6F6F6"><td align="center" height="25">新闻样式:</td><td><input name="jibie" type="radio" value="0" checked>
          中文版</td></tr>
  <tr>
    <td width="15%" height="25" align="right" bgcolor="#F6F6F6">文章类型:</td>
    <td width="85%" bgcolor="#FFFFFF">
<%
    sql = "select * from kml_bclass"
    rs.open sql,conn,1,1
 if rs.eof and rs.bof then
 response.write "请先添加栏目。"
 response.end
 else
%>
<select name="bclassid" onChange="changelocation(document.myform.bclassid.options[document.myform.bclassid.selectedIndex].value)" size="1">
        <option selected value="<%=trim(rs("bclassid"))%>"><%=trim(rs("bclassname"))%></option>
        <%dim selclass
         selclass=rs("bclassid")
        rs.movenext
        do while not rs.eof
%>
<option value="<%=trim(rs("bclassid"))%>"><%=trim(rs("bclassname"))%></option>
<%
rs.movenext
loop
end if
rs.close
%>
      </select>
      <select name="sclassid">
<%
sql="select * from kml_sclass where bclassid="&selclass
rs.open sql,conn,1,1
if not(rs.eof and rs.bof) then
%>
        <option selected value="<%=rs("sclassID")%>"><%=rs("sclassname")%></option>
<%
rs.movenext
do while not rs.eof
%>
<option <%if RsEdit("sclassid")=rs("sclassID") then %> selected <% end if %>value="<%=rs("sclassID")%>"><%=rs("sclassname")%></option>
<%
rs.movenext
loop
end if
        rs.close
        set rs = nothing
%>
</select>