从下面您将看到我从表school
中检索了数据。接下来,我试图从班级与该学校相关的class
表中导出数据。为了尝试实现这一目标,我在被选中的学校上设置了一个名为Scn
的变量。
唉,无论出于何种原因,我都无法阅读变量。该变量被确认为通过警告声明设置,我可以选择一个学校等于(比如说)1的课程,但是为了所有人的爱,我无法获得select语句来显示数据所在的类别等于变量。
<SELECT NAME="ListBox1" SIZE=1 onchange="scname(this)">
<% Set conn = Server.CreateObject("ADODB.Connection") %>
<%conn.connectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;" &_
"Data source = \\mockcourt.mdb"
Conn.Open%>
<% Set rs = conn.Execute("SELECT * FROM school") %>
<% Do While Not rs.EOF ' define the ListBox OPTIONs %>
<OPTION VALUE="<%= rs("schoolKey") %>"> <%= rs("school") %>
<% rs.MoveNext %>
<% Loop %>
<% rs.Close %>
<% conn.Close %>
</SELECT>
<script type="text/javascript">
function scname(target){
var Scn = target.value
alert("You changed to "+ Scn)
}
</script>
<SELECT NAME="ListBox2" SIZE=1 onChange="clname(this)">
<% Set conn = Server.CreateObject("ADODB.Connection") %>
<%conn.connectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;" &_
"Data source = \\ mockcourt.mdb"
Conn.Open%>
<% Set rs = conn.Execute("SELECT * FROM class WHERE school = '"+Scn+"'") %>
<% Do While Not rs.EOF ' define the ListBox OPTIONs %>
<% tba=Scn %>
<OPTION VALUE="<%= rs("school") %>,<%= rs("classname") %>"> <%= rs("classname") %>
<% rs.MoveNext %>
<% Loop %>
<% rs.Close %>
<% conn.Close %>
</select>
答案 0 :(得分:0)
Scn
在您的scname()
函数中声明。这意味着它的范围在该函数内,并且不能在它之外使用。
答案 1 :(得分:0)
假设您所有的dropdwons都是名为“myform”的形式,并且表单操作为空或被定义为您的页面,请尝试以下操作:
<% Set conn = Server.CreateObject("ADODB.Connection")
conn.connectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;" &_
"Data source = \\ mockcourt.mdb"
Conn.Open
set rs=Server.CreateObject("ADODB.recordset")
dim Scn
Scn=request("ListBox1") & "" ' to make sure that Scn is not null in any case
%>
<select NAME="ListBox1" onChange="clname(this)">
<% Set rs = conn.Execute("SELECT * FROM school")
Do While Not rs.EOF ' define the ListBox OPTIONs
if Scn=rs("schoolKey") then%>
<OPTION VALUE="<%= rs("schoolKey") %>" selected> <%= rs("school") %></option>
<% else %>
<OPTION VALUE="<%= rs("schoolKey") %>"> <%= rs("school") %></option>
<%
end if
rs.MoveNext
Loop %>
</SELECT>
<% set rs=nothing %>
<script type="text/javascript">
function scname(target){
var Scn = target.value
alert("You changed to "+ Scn)
document.forms["myform"].submit();
}
</script>
<SELECT NAME="ListBox2" SIZE=1>
<%
set rs=Server.CreateObject("ADODB.recordset")
Set rs = conn.Execute("SELECT * FROM class WHERE school = '"+Scn+"'")
Do While Not rs.EOF ' define the ListBox OPTIONs
tba=Scn %>
<OPTION VALUE="<%= rs("school") %>,<%= rs("classname") %>"> <%= rs("classname") %></option>
<% rs.MoveNext
Loop %>
</select>
<% set rs=nothing
conn.Close %>
将HTML标记,输入关闭甚至图像视为一种好习惯。如果你计划在必须遵守某种标准的公司内工作,那就习惯了。