版主救命:关于二级联动下拉菜单问题。
版主:救命啊.........
在发表新闻时,如是专题新闻,需要选择专栏名称及分栏名称,而有的专栏可能又无分栏。我做了个二级联动下拉菜单:专栏与分专栏联动,选择专栏时将相应的分当栏找出。判断是否是专题新闻,用个IsColumn字段判断。但问题是:
1、 如我选择了专题新闻时,我选择了专栏名称,但又不需要选择分专栏名称时,程序会出错;
2、 如我选择了专题新闻时,忘记选择专栏与分专栏名称,程序也出错。
如何避免这个问题,是不是将专栏与分专栏名称的默认值设为Null就行,但又怎么设?
请版主救命!!!!!!!!!!!
Access数据库:defColunInfo(专栏): ColumnID(专栏ID),Column(专栏名称),IsCurrent
defColumndtl(分专栏):SubColumnID(分专栏ID),ColumnID(专栏ID),,SubColumn(分专栏名称),IsCurrent
asp代码:
<!-- #include file="conn.asp"-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>二级联动菜单</title>
<script language=JavaScript>
<%
dim sql,i,j
set rs_Column= server.createobject("adodb.recordset")
sql="select * from defColunInfo order by ColumnID"
rs_Column.open sql,conn2,1,1
%>
var selects=[];
selects['yyy']=new Array(new Option('分栏名称','yyy'));
<%
for i=1 to rs_Column.recordcount
%>
selects['<%=rs_Column("ColumnID")%>']=new Array(
<%
set rs_SubColumn= server.createobject("adodb.recordset")
sql="select * from defColumndtl where ColumnID="&rs_Column("ColumnID")&" order by SubColumnID"
rs_SubColumn.open sql,conn2,3,2
if rs_SubColumn.recordcount>0 then
for j=1 to rs_SubColumn.recordcount
if j=rs_SubColumn.recordcount then
%>new Option('<%=trim(rs_SubColumn("SubColumn"))%>','<%=trim(rs_SubColumn("SubColumnID"))%>'));
<%else%>
new Option('<%=trim(rs_SubColumn("SubColumn"))%>','<%=trim(rs_SubColumn("SubColumnID"))%>'),
<%
end if
rs_SubColumn.movenext
next
else
%>
new Option('','0'));
<%
end if
rs_SubColumn.close
set rs_SubColumn=nothing
rs_Column.movenext
next
rs_Column.close
set rs_Column=nothing
%>
function chsel(){
with (document.form1){
if(Column_select.value!="yyy") {
SubColumn_select.options.length=0;
SubColumn_select.add(selects['yyy'][0]);
for(var i=0;i<selects[Column_select.value].length;i++){
SubColumn_select.add(selects[Column_select.value][i]);
}
}
}
}
</script>
</head>
<body>
<form id="form1" name="form1" method="POST" action="SaveForNotSend.asp?ID=<%=ERs("ID")%>">
<!--//////////////////////////Column_select下拉列表//////////////////////////-->
<select name="Column_select" onChange=chsel()>
<option value="xxx" selected>请选择专栏名称</option>
<%
dim tmpid '定义一个临时变量用来记住省id
tmpid=0
set rs_Column=server.CreateObject("ADODB.recordset")
sql="select * from defColunInfo order by ColumnID Desc"
rs_Column.open sql,conn2,3,2
while not rs_Column.eof
tmpid=rs_Column("ColumnID")
%>
<option value="<%=rs_Column("ColumnID")%>" ><%=trim(rs_Column("Column"))%></option>
<%
'response.Write form1.Column_select.value
rs_Column.movenext
wend
rs_Column.close
set rs_Column=nothing
%>
</select>
<!--//////////////////////////SubColumn_select下拉列表//////////////////////////-->
<select name="SubColumn_select">
<option value="SubColumnID" selected="selected">-分栏名称-</option>
</select>
<p align="center">
<input type="submit" name="Submit" value="上传" onClick="submitform(forms[0]);"/>
<input type="submit" name="Submit2" value="重写" />
</p>
<input type="hidden" name="MM_update" value="form1">
<input type="hidden" name="MM_recordId" value="<%= ERs("ID")%>">
</FORM>
</body>
</html>