二级联问题,问题解决,马上高分报答!!!

xiao8835452 2004-04-12 04:06:07
本人想创建一个年级与班级的选择菜单(select),年级与班级都存在数据库中.当选择一个年级后,班级选择菜单自动显示该年级所包括的班级,本人写了以下的源码,请各位高手改一下错,或者干脆帮我写个,马上高分相送!
<!--#include file=conn.asp -->
<form name="myform">
<select name="zhuanye" size="1" id="zhuanye" onchange="changezhuanye(document.myform.zhuanye.options[document.myform.zhuanye.selectedIndex].value)">
</select>
<select name="subject" size="1" id="subject">
</select>
</form>
<%
set rs= Server.CreateObject("adodb.recordset")
sql="select zhuanye,subject from subject where acadamy_id=1"
rs.open sql,conn,1,1%>
<script language = "JavaScript">
var subject = new Array();
var c;
<%i=0;
if not rs.EOF then
do while not rs.eof
%>
subject[<%=i %>]=new Array("<%= rs("zhuanye") %>","<%= rs("subject") %>");
<%
i=i+1
rs.movenext
loop
rs.close
set rs=nothing
end if
%>
c=<%= i %>;
xiaoli();
function xiaoli(){
var k;
document.myform.zhuanye.length=0;
for (k=0,k<c;k++){
document.myform.zhuanye.options[document.myform.zhuanye.length]=new option(subject[k][0],subject[k][0]);

}
}
function changezhuanye(zhuanyename) {
var j,b;
selectname=zhuanyename;
document.myform.subject.length=0;
for (j=0,j<c;j++){
if subject[j][0]==selectname{
document.myform.subject.options[document.myform.subject.length]=new option(subject[j][1],subject[j][1]);
}
}
}
</script>
...全文
42 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
lewisdoll 2004-04-12
  • 打赏
  • 举报
回复
'''''''''''''''''''''c_fun.asp

<!--#include file="global.asp"-->
<%response.CacheControl = "no-cache" %>
<!--
JobList = new Array();
var CorpIndex = -1;
var JobIndex;

function newCorp(){
CorpIndex++;
JobList[CorpIndex] = new Array();
JobList[CorpIndex][0] = new aJob( "请选择 ", "0") ;
JobIndex = 1;
}

function addJob( Job, value ) {
JobList[CorpIndex][JobIndex] = new aJob(Job, value);
JobIndex++;
}

function aJob( text, value ) {
this.text = text;
this.value = value;
}

function updateJob( topic ) {
//topic++;
with (document.apply.jobid) {
newCorp = JobList[topic].length;
oldTopics = options.length;

// add new Job to the menu
for ( i=0; i<newCorp; i++ ) {
options[i] = new Option( JobList[topic][i].text,
JobList[topic][i].value );
}

// remove any left from previous menu
for ( i=oldTopics-1; i>=newCorp; i-- ) {
options[i] = null;
}

// select the top item so it shows up in the dialog
options[0].selected = true;
}
}
function CJobTitle(jobid)
{
var myfrm = document.apply;
myfrm.jobtitle.value = myfrm.jobid.options[myfrm.jobid.selectedIndex].text;
//myfrm.jobtitle.value = myfrm.jobid.;
}

<%
dim rs,rsf
dim tstr,arrTstr,tstr1
tstr = "":tstr1=""
'获取所有公司ID及名称
set rs=conn.execute("select * from company order by companyid")
if not rs.eof and not rs.bof then
do while not rs.eof
response.Write("newCorp();" & vbnewline)
set rsf=conn.execute("select * from job where companyid="&rs("companyid")&"")
if not rsf.eof and not rsf.bof then
do while not rsf.eof
response.Write("addJob(""" & rsf("jobtitle") & """,""" & rsf("jobid") & """);" & vbnewline)
rsf.movenext
loop
else
response.Write("addJob(""暂无招聘信息"",""0"");" & vbnewline)
end if
rsf.close
rs.movenext
loop
end if
rs.close
set rs=nothing
set rsf=nothing
closedb
%>

//-->

''''''''''调用方法

<tr bgcolor="#FFFFFF">
<td width="18%" align="center" bgcolor="#F3F3F3">申请职位</td>
<td width="82%"><select name="corp" id="corp" onChange="updateJob(this.selectedIndex);">
<%
dim rs_kk,sqlk
sqlk="select companyid,company from company order by companyid"
set rs_kk = server.CreateObject("ADODB.Recordset")
rs_kk.open sqlk,conn,1,1
if not rs_kk.eof and not rs_kk.bof then
do while not rs_kk.eof
response.Write "<option value="&rs_kk("companyid")
if ""<>trim(request("company")) and (not isnull(request("company"))) and cint(request("company"))=rs_kk("companyid") then response.write " selected"
response.write ">"&rs_kk("company")&"</option>"
rs_kk.movenext
loop
rs_kk.close
end if
sqlk=""
%>
</select>
<select name="jobid" id="jobid" onChange="CJobTitle(this.selectedIndex);">
<option value="">请选择</option>
</select><input name="jobtitle" type="hidden" value=""></td>
</tr>
<script src="c_fun.asp" language="javascript"></script>
<script language="javascript">updateJob(0);</script>


里面的SQL及ASP自己改下吧。程序测试通过!!

28,408

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧